[Solved]-Select ForeignKey field in form ChoiceField

33đź‘Ť

âś…

Perhaps you’re looking for ModelChoiceField ?

To use it, you would write something like:

class VehicleForm(forms.Form):
   series = ModelChoiceField(queryset=Series.objects.all()) # Or whatever query you'd like

Then do the same for the other fields.

Of course, you would probably use a ModelForm but that’s just an example. Is that what you’re looking for?

👤Bartek

Leave a comment