Opened 3 years ago

Closed 2 years ago

#18388 closed New feature (fixed)

Add more hooks in the ModelAdmin (get_extra, get_max_num)

Reported by: d.willy.c.c@… Owned by: timo
Component: contrib.admin Version: 1.4
Severity: Normal Keywords:
Cc: areski@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

in class InlineModelAdmin and def get_formset in line 1401
defaults = {

"form": self.form,
"formset": self.formset,
"fk_name": self.fk_name,
"fields": fields,
"exclude": exclude,
"formfield_callback": partial(self.formfield_for_dbfield, request=request),
"extra": self.extra,
"max_num": self.max_num,
"can_delete": can_delete,

}

I think that is more customizable code should be as follows
"form": self.form,

"formset": self.formset,
"fk_name": self.fk_name,
"fields": fields,
"exclude": exclude,
"formfield_callback": partial(self.formfield_for_dbfield, request=request),
"extra": self.get_extra(),
"max_num": self.get_max_num(),
"can_delete": can_delete,

Attachments (4)

ticket_18338.diff (2.8 KB) - added by Melevir 3 years ago.
ticket_18338.2.diff (1.0 KB) - added by Melevir 3 years ago.
This patch is correct. There was some garbage in previous one, sorry for that.
patch_ticket_18338.3.txt (4.4 KB) - added by areski 2 years ago.
patch_ticket_18338.4.txt (9.6 KB) - added by areski 2 years ago.

Download all attachments as: .zip

Change History (18)

comment:1 Changed 3 years ago by rasca

  • Easy pickings set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from problematic code in InlineModelAdmin to Add more hooks in the ModelAdmin (get_extra, get_max_num)
  • Triage Stage changed from Unreviewed to Accepted

This is in tone with #17646, #17006 and #16841.

I'm accepting this based on that they are similar to the other ones, adding hooks to the ModelAdmin.

Maybe we can think a way to add this "hooks" in a more DRY way than adding a function get_FOO(self, request): return self.FOO

comment:2 Changed 3 years ago by anonymous

I think 'GET' is the easiest way to personalize this, and also believe that all variables should have a 'GET'

comment:3 Changed 3 years ago by vane.gomesl@…

  • Owner changed from nobody to anonymous

comment:4 Changed 3 years ago by vanessagomes

  • Owner changed from anonymous to vanessagomes

comment:5 Changed 3 years ago by vanessagomes

  • Owner changed from vanessagomes to nobody

comment:6 Changed 3 years ago by Melevir

  • Owner changed from nobody to Melevir
  • Status changed from new to assigned

Changed 3 years ago by Melevir

comment:7 Changed 3 years ago by Melevir

  • Has patch set

comment:8 Changed 3 years ago by Melevir

  • Has patch unset

Changed 3 years ago by Melevir

This patch is correct. There was some garbage in previous one, sorry for that.

comment:9 Changed 3 years ago by Melevir

  • Has patch set

comment:10 Changed 2 years ago by javimansilla

#19425 is proposing something similar and IMHO it's doing it on a better way

comment:11 Changed 2 years ago by areski

I agree also that #19425 is more elegant, I rebased the patch from that ticket and added max_num as per the suggestion here.
See patch in attachment and the PR : https://github.com/django/django/pull/1155

Changed 2 years ago by areski

Changed 2 years ago by areski

comment:12 Changed 2 years ago by areski

  • Cc areski@… added

Just updated the patch to add some documentation

comment:13 Changed 2 years ago by timo

  • Owner changed from Melevir to timo

InlineModelAdmin.get_extra was added in #19425. I'll try to review and commit the second half of this.

comment:14 Changed 2 years ago by Tim Graham <timograham@…>

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

In 61524b09cfa3b51643d0e79cbf0e1e08ede357ae:

Fixed #18388 - Added InlineModelAdmin.get_max_num hook.

Thanks d.willy.c.c@ for the suggestion and Melevir and Areski Belaid for work
on the patch.

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