I have three models:
System_ContactSystemContact_list
The Contact_List model has two fields: contact and sys and, not surprisingly, is just a manyToMany model to associate a list of contacts to each system. I have modelForm for adding a new contact to the system’s list of contacts:
class Add_Contact_Form(ModelForm):
class Meta:
model = Contact_List
fields = ('contact',)
Simple, right? My confusion is this: Even thought the Contact_List model has many many duplicate contacts (because one contact can be associated with many systems) each contact is only displayed once within the form’s Select widget.
Why?!
I mean, this is a great default behaviour for my purposes, but I want to make sure this is actually the correct default behaviour that I can rely on, not some random error I have done that just happens to work out for me now.
It’s not that it’s default behaviour, it’s that the select widget in your contact_list form is displaying all of the entries that are from the contact table.
Every model is a table in the database, therefore you have 3 tables:
If this is what you are trying to do, you should have the following:
This means that every row in the ContactList table is a relationship between a particular machine from the system table and a list of contacts from the contact table