Code

Opened 5 years ago

Closed 3 years ago

#9588 closed New feature (fixed)

provide **kwargs argument to GenericInlineModelAdmin.get_formset

Reported by: lakin@… Owned by: brosner
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 prestontimmons 3 years ago.
9588.2.diff (2.4 KB) - added by prestontimmons 3 years ago.
Added tests. Patched against r16231.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 5 years ago by brosner

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to brosner
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

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

comment:2 Changed 5 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 4 years ago by brosner

  • milestone set to 1.2
  • Version changed from 1.0 to SVN

comment:4 Changed 4 years ago by ubernostrum

  • milestone 1.2 deleted

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

comment:5 Changed 3 years ago by gabrielhurley

  • Component changed from Contrib apps to contrib.contenttypes

comment:6 Changed 3 years ago by julien

  • Needs tests set
  • Severity set to Normal
  • Type set to New feature

Changed 3 years ago by prestontimmons

comment:7 Changed 3 years ago by prestontimmons

  • Easy pickings unset
  • Needs tests unset

comment:8 Changed 3 years ago by julien

  • 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 3 years ago by prestontimmons

Added tests. Patched against r16231.

comment:9 Changed 3 years ago by prestontimmons

  • Needs tests unset

comment:10 Changed 3 years ago by julien

  • Triage Stage changed from Accepted to Ready for checkin

Excellent, thanks a lot.

comment:11 Changed 3 years ago by jezdez

  • Resolution set to fixed
  • Status changed from assigned to closed

In [16419]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.