[Answer]-Django Save Many to Many Field – no default value

1πŸ‘

βœ…

On this:

vquestions = models.ManyToManyField(Questions, blank = True, null = True, choices = VID_QUESTIONS)

Try using limit_choices_to (docs) instead of defining a set of choices with choices =. This can be done on the model and will impact the available choices on all modelforms where that model is used. That also means you don’t have to define a queryset in forms.py; you can pass an additional parameter to limit_choices_to to only allow associations with approved questions.

Since you are using commit = False with a form that touches a many-to-many field, I believe you will also need to use save_m2m (docs) in order to get things to save properly.

πŸ‘€souldeux

Leave a comment