Opened 13 years ago
Closed 12 years ago
#18388 closed New feature (fixed)
Add more hooks in the ModelAdmin (get_extra, get_max_num)
Reported by: | Owned by: | Tim Graham | |
---|---|---|---|
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)
Change History (18)
comment:1 by , 13 years ago
Easy pickings: | set |
---|---|
Summary: | problematic code in InlineModelAdmin → Add more hooks in the ModelAdmin (get_extra, get_max_num) |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 13 years ago
I think 'GET' is the easiest way to personalize this, and also believe that all variables should have a 'GET'
comment:3 by , 13 years ago
Owner: | changed from | to
---|
comment:4 by , 13 years ago
Owner: | changed from | to
---|
comment:5 by , 13 years ago
Owner: | changed from | to
---|
comment:6 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 12 years ago
Attachment: | ticket_18338.diff added |
---|
comment:7 by , 12 years ago
Has patch: | set |
---|
comment:8 by , 12 years ago
Has patch: | unset |
---|
by , 12 years ago
Attachment: | ticket_18338.2.diff added |
---|
This patch is correct. There was some garbage in previous one, sorry for that.
comment:9 by , 12 years ago
Has patch: | set |
---|
comment:10 by , 12 years ago
#19425 is proposing something similar and IMHO it's doing it on a better way
comment:11 by , 12 years ago
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
by , 12 years ago
Attachment: | patch_ticket_18338.3.txt added |
---|
by , 12 years ago
Attachment: | patch_ticket_18338.4.txt added |
---|
comment:13 by , 12 years ago
Owner: | changed from | to
---|
InlineModelAdmin.get_extra
was added in #19425. I'll try to review and commit the second half of this.
comment:14 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
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