Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strike></p> <pre><code>class SwallowForm(forms.Form): airspeed_velocity = forms.IntegerField() is_migratory = forms.BooleanField() class AfricanSwallowForm(forms.ModelForm, SwallowForm): class Meta: model = AfricanSwallow class EuropeanSwallowForm(forms.Form, SwallowForm): ... </code></pre> <p>Should work. </strike></p> <p>I have some long running code that works and has the fields attr that looks like this.</p> <pre><code>languages_field = forms.ModelMultipleChoiceField( queryset=Language.objects.all(), widget=forms.CheckboxSelectMultiple, required=False ) class FooLanguagesForm(forms.ModelForm): languages = languages_field class Meta: model = Foo fields = ('languages', ) </code></pre> <p><strike>Notice that I still use the fields tuple in Meta.</strike> The field shows up in the fields dict on the form instance whether or not it is in the Meta.fields.</p> <p>I have a regular form that uses this pattern as well:</p> <pre><code>genres_field = forms.ModelMultipleChoiceField( queryset=blah, widget=forms.CheckboxSelectMultiple, #required=False, ) class FooGenresForm(forms.Form): genres = genres_field </code></pre> <p>I see that my fields dict is working.</p> <pre><code>In [6]: f = FooLanguagesForm() In [7]: f.fields Out[7]: {'languages': &lt;django.forms.models.ModelMultipleChoiceField object at 0x1024be450&gt;} In [8]: f2 = FooGenresForm() In [9]: f2.fields Out[9]: {'genres': &lt;django.forms.models.ModelMultipleChoiceField object at 0x1024be3d0&gt;} </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload