I'm having some difficulties with Django's ModelChoiceField.
I wrote the following code:
class BookForm(ModelForm):
publisher = forms.ModelChoiceField(queryset=Publisher.objects.all())
...
Now Book and Publisher are related this way: Book → Library → SubPublisher → Publisher. All relations were made using ForeignKey.
My form is like that:
- Publisher (ModelChoiceField)
- SubPublisher (ModelChoiceField with autocomplete widget that filters according to Publisher selection)
- Library (same as SubPublisher, filters according to SubPublisher)
My problem is that I can't get ModelChoiceField to select the relevant Publisher out of the publishers list.
Note: Publisher & SubPublisher are only there to filter on Libraries - and it works, the issue is only about setting initial values according to selected Library's ForeignKeys.
What am I missing?