[Django]-Displaying initial data in dropdown list in django

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

👤xbello

Leave a comment