3👍
✅
Here’s what I’m doing:
class CourseChoicesForm(forms.ModelForm):
courseoption = forms.ModelChoiceField(Courses.objects.all())
The Django engine take care for you of making the list of tuples to fill the ChoiceField. The Courses.objects.all()
can be any queryset.
https://docs.djangoproject.com/en/dev/ref/forms/fields/#fields-which-handle-relationships
Source:stackexchange.com