Opened 13 years ago

Closed 12 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: dev
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

Description

hi,

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:
http://stackoverflow.com/questions/7310861/django-passing-parameters-to-inline-formset

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
ModelForm).
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
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 by Melvyn Sopacua, 12 years ago

Component: FormsDocumentation
Triage Stage: UnreviewedDesign decision needed
Version: 1.3master

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 by Aymeric Augustin, 12 years ago

Resolution: wontfix
Status: newclosed

The comment above makes sense.

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