Opened 8 years ago

Closed 5 years ago

#9588 closed New feature (fixed)

provide **kwargs argument to GenericInlineModelAdmin.get_formset

Reported by: lakin@… Owned by: Brian Rosner
Component: contrib.contenttypes Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX:

Description

InlineModelAdmin.get_formset provides kwargs to override defaults:

    def get_formset(self, request, obj=None, **kwargs):
        """Returns a BaseInlineFormSet class for use in admin add/change views."""
        if self.declared_fieldsets:
            fields = flatten_fieldsets(self.declared_fieldsets)
        else:
            fields = None
        if self.exclude is None:
            exclude = []
        else:
            exclude = self.exclude
        defaults = {
            "form": self.form,
            "formset": self.formset,
            "fk_name": self.fk_name,
            "fields": fields,
            "exclude": exclude + kwargs.get("exclude", []),
            "formfield_callback": self.formfield_for_dbfield,
            "extra": self.extra,
            "max_num": self.max_num,
        }
        defaults.update(kwargs)
        return inlineformset_factory(self.parent_model, self.model, **defaults)

Shouldn't we do the same for GenericInlineModelAdmin.get_formset ?

Potential Patch:

    def get_formset(self, request, obj=None, **kwargs):
        if self.declared_fieldsets:
            fields = flatten_fieldsets(self.declared_fieldsets)
        else:
            fields = None
        defaults = {
            "ct_field": self.ct_field,
            "fk_field": self.ct_fk_field,
            "form": self.form,
            "formfield_callback": self.formfield_for_dbfield,
            "formset": self.formset,
            "extra": self.extra,
            "can_delete": True,
            "can_order": False,
            "fields": fields,
        }
        defaults.update(kwargs)
        return generic_inlineformset_factory(self.model, **defaults)

I chose the "Contrib Apps" component because there is no "contrib.contenttypes".

Attachments (2)

9588.diff (885 bytes) - added by Preston Timmons 6 years ago.
9588.2.diff (2.4 KB) - added by Preston Timmons 6 years ago.
Added tests. Patched against r16231.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 8 years ago by Brian Rosner

Owner: changed from nobody to Brian Rosner
Status: newassigned
Triage Stage: UnreviewedAccepted

I was just thinking about this today as I was going through this code.

comment:2 Changed 8 years ago by anonymous

If you're having a go at fixing this one, you should consider fixing #9122 at the same time, it's kinda related in the "Make the GenericInlineModelAdmin more like the InlineModelAdmin" category. :)

comment:3 Changed 7 years ago by Brian Rosner

milestone: 1.2
Version: 1.0SVN

comment:4 Changed 7 years ago by James Bennett

milestone: 1.2

1.2 is feature-frozen, moving this feature request off the milestone.

comment:5 Changed 6 years ago by Gabriel Hurley

Component: Contrib appscontrib.contenttypes

comment:6 Changed 6 years ago by Julien Phalip

Needs tests: set
Severity: Normal
Type: New feature

Changed 6 years ago by Preston Timmons

Attachment: 9588.diff added

comment:7 Changed 6 years ago by Preston Timmons

Easy pickings: unset
Needs tests: unset

comment:8 Changed 6 years ago by Julien Phalip

Needs tests: set

Thanks a lot for the patch. It is a simple change but tests are still needed. Passing a couple of kwargs and making sure that they override the defaults would be enough.

Changed 6 years ago by Preston Timmons

Attachment: 9588.2.diff added

Added tests. Patched against r16231.

comment:9 Changed 6 years ago by Preston Timmons

Needs tests: unset

comment:10 Changed 6 years ago by Julien Phalip

Triage Stage: AcceptedReady for checkin

Excellent, thanks a lot.

comment:11 Changed 5 years ago by Jannis Leidel

Resolution: fixed
Status: assignedclosed

In [16419]:

Fixed #9588 -- Allow passing kwargs to GenericInlineModelAdmin.get_formset just like the InlineModelAdmin. Thanks, prestontimmons.

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