Opened 16 years ago

Closed 13 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: dev
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: no

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 13 years ago.
9588.2.diff (2.4 KB ) - added by Preston Timmons 13 years ago.
Added tests. Patched against r16231.

Download all attachments as: .zip

Change History (13)

comment:1 by Brian Rosner, 16 years ago

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 by anonymous, 16 years ago

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 by Brian Rosner, 15 years ago

milestone: 1.2
Version: 1.0SVN

comment:4 by James Bennett, 15 years ago

milestone: 1.2

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

comment:5 by Gabriel Hurley, 14 years ago

Component: Contrib appscontrib.contenttypes

comment:6 by Julien Phalip, 14 years ago

Needs tests: set
Severity: Normal
Type: New feature

by Preston Timmons, 13 years ago

Attachment: 9588.diff added

comment:7 by Preston Timmons, 13 years ago

Easy pickings: unset
Needs tests: unset

comment:8 by Julien Phalip, 13 years ago

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.

by Preston Timmons, 13 years ago

Attachment: 9588.2.diff added

Added tests. Patched against r16231.

comment:9 by Preston Timmons, 13 years ago

Needs tests: unset

comment:10 by Julien Phalip, 13 years ago

Triage Stage: AcceptedReady for checkin

Excellent, thanks a lot.

comment:11 by Jannis Leidel, 13 years ago

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