Reputation: 3672
I would like to display all the field names of a table in a drop down list. Here is my form:
sortFields=forms.ModelChoiceField(queryset=ActsInformationModel._meta.get_all_field_names(), empty_label="Select the sort field")
I get the error 'list' object has no attribute 'all'.
What's wrong?
Thanks in advance,
Romain
Upvotes: 0
Views: 1553
Reputation: 39659
You need a ChoiceField here:
choices = [(i, i) for i in ActsInformationModel._meta.get_all_field_names()]
sortFields = forms.ChoiceField(label='Sort',
choices=choices)
Upvotes: 1