Opened 4 years ago

Closed 3 years ago

#18185 closed Bug (wontfix)

inlineformset_factory: formfield_callback does not execute for custom fields on modelForm

Reported by: kush420 Owned by: nobody
Component: Documentation Version: master
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
Easy pickings: no UI/UX: 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: 

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/ -> def fields_for_model -> line 146

It appears that formfield_callback will get executed for fields on
model ONLY.

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

Formfield_callback is not documented at all and this may be intentional. If it's not the intentional then it is a doc and perhaps a naming issue. Formfield_callback is not something that calls home once it has created a form field -- it is a function that should supply the formfield for a model field instead of the default field.formfield(). As such, it doesn't make sense to call this function for fields that are not part of a model and already defined on the form.

comment:2 Changed 3 years ago by aaugustin

  • Resolution set to wontfix
  • Status changed from new to closed

The comment above makes sense.

Note: See TracTickets for help on using tickets.
Back to Top