inlineformset_factory: formfield_callback does not execute for custom fields on modelForm
|Reported by:||kush420||Owned by:||nobody|
|Severity:||Normal||Keywords:||inlineformset_factory modelform formfield_callback custom fields|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I'm on django 1.3 using class based generic views.
So in my use case, i have a modelForm defined with custom fields.
something along the lines of
class MF_B(forms.ModelForm): stuff = forms.MultipleChoiceField(queryset=None, required=False) class Meta: model=B
as the code above implies, I want to populate the stuff choices here
with a queryset.
Model B also has a foreign key to Model A such that i would call
inlineformset_factor like so:
AB_Formset = inlineformset_factory(A, B, form=MF_B, max_num=3, formfield_callback=self.get_field_qs)
Just pretend get_field_qs is in scope and what we are trying to do
here is something like:
My expectation here is that get_field_qs would get called for ALL
fields on the form (i.e. including my custom fields on the
That doesn't happen.
Looking at the django code, if i go to
django/forms/models.py -> def fields_for_model -> line 146
It appears that formfield_callback will get executed for fields on
Because the name of the parameter is formfield_callback, I would
expect get_field_qs would be called for all the fields.
As a result I feel this is a bug.
Change History (2)
comment:1 Changed 3 years ago by msopacua
- Component changed from Forms to Documentation
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Design decision needed
- Version changed from 1.3 to master