I am learning Django and have hit an inssue that I don't know what to Google for. I have the standard User model and a Profile model that points into the User model via a OneToOne field. That part plus the profile's Form and the CBVs all work.
A profile holder can have one or more professional affiliations. This is not for a union but my Dad, for example, as a welder, was affiliated with: "The Iron Workers", "Steam Fitters", "Boiler Makers", "Pipe Fitters" and a couple other specific unions that used welders. So if I want the profile and form to allow multiple choices and multiple selected results for affiliations then I see that you might use
class Profile(models.Model):
GROUPS = (
('IW', 'Iron Workers'),
('PF', 'Pipe Fitters'),
...
)
affiliation = models.CharField(
max_length=3,
choices=RANK,
default='U',
blank=True,
null=True,
)
...
In the associated form it looks like you use a
GROUPS = (
('IW', 'Iron Workers'),
('PF', 'Pipe Fitters'),
...
)
affiliation = forms.MultipleChoiceField(
choices=GROUPS
)
What if I want a db table of these choice items instead of tuples? If I have to add to a list of choices then editing the code might not be the most convenient response. Maybe the list of groups should be in the Django admin area.
How do I tell the model and form to look in a separate db table for the possible values and then how do I modify the model and form to allow for zero or more group affiliations?