Populating ChoiceField from the database

I would like to have several fields in my form that display as ChoiceFields that get their contents from the database.

I thought something like:

class SeriesForm(ModelForm): series = forms.ChoiceField(choices=Series.objects.all()) class Meta: model = Series exclude = ('model', 'date_added',) 

But the series field no longer appears at all in my form. What am I missing?

After trying to solve (using ModelChoiceField ), I still see the same problem. Here is my code:

 series = forms.ModelChoiceField(queryset=Series.objects.values('series'), empty_label=" ") 
+4
source share
1 answer

Source: https://habr.com/ru/post/1300055/


All Articles