I have a form that has a field which allows the user to select multiple options from the field's options (forms.ModelMultipleChoiceField). I would think the appropriate model would need to be a many to many relationship but I am not sure how to structure it or how it would look in the actual database. How would this ManyToMany relationship look in mysql? Let me know if more information is needed, I'm pretty new to this.

in my forms.py:

class ProjectForm(forms.ModelForm):

    role = forms.ModelMultipleChoiceField(ProjectRole.objects, ..., a bunch of form modifiers,)

in my models.py:

class ProjectRole(models.Model):

    role_name = models.CharField(max_length=100)
    def __str__(self):
        return '%s' % self.role_name

class Project(models.Model):

    role = models.ManyToManyField(ProjectRole, ... extra stuff...)
New contributor
Noah Sandler is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • You may get more and better answers at stackoverflow. There are likely more django users there. – Lennart Jun 29 at 18:30

Your Answer

Noah Sandler is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.