I have the following Django models:
class Contact(models.Model):
id #primary key
#Other contact info
class ContactType(models.Model):
contacttype_choices=(('Primary', 'Primary'),
('Billing', 'Billing'),
('Business', 'Business'),
('Technology', 'Technology'))
contact=models.ForeignKey(Contact)
type=models.CharField(choices=contacttype_choices, max_length=30)
class Meta:
unique_together=('contact', 'type')
So any contact object can have up to four contact types, with each type either being present or absent. I would like to make a Model Form for Contact
with a multiple choice field for contact type. How can I populate this contact type field with the existing values when I construct the Contact form with a Contact instance?
Edit: To clarify, I want one checkbox to be created for each of those four choices, and if the form is instantiated with a model instance, then I want the checkboxes to be checked for each of the related objects that exists, similar to what happens automatically with the rest of the fields.