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: d.willy.c.c@… 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)

ticket_18338.diff (2.8 KB ) - added by Lebedev Ilya 12 years ago.
ticket_18338.2.diff (1.0 KB ) - added by Lebedev Ilya 12 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 Belaid 12 years ago.
patch_ticket_18338.4.txt (9.6 KB ) - added by Areski Belaid 12 years ago.

Download all attachments as: .zip

Change History (18)

comment:1 by rasca, 13 years ago

Easy pickings: set
Summary: problematic code in InlineModelAdminAdd more hooks in the ModelAdmin (get_extra, get_max_num)
Triage Stage: UnreviewedAccepted

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 by anonymous, 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 vane.gomesl@…, 13 years ago

Owner: changed from nobody to anonymous

comment:4 by vanessagomes, 13 years ago

Owner: changed from anonymous to vanessagomes

comment:5 by vanessagomes, 13 years ago

Owner: changed from vanessagomes to nobody

comment:6 by Lebedev Ilya, 12 years ago

Owner: changed from nobody to Lebedev Ilya
Status: newassigned

by Lebedev Ilya, 12 years ago

Attachment: ticket_18338.diff added

comment:7 by Lebedev Ilya, 12 years ago

Has patch: set

comment:8 by Lebedev Ilya, 12 years ago

Has patch: unset

by Lebedev Ilya, 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 Lebedev Ilya, 12 years ago

Has patch: set

comment:10 by javimansilla, 12 years ago

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

comment:11 by Areski Belaid, 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 Areski Belaid, 12 years ago

Attachment: patch_ticket_18338.3.txt added

by Areski Belaid, 12 years ago

Attachment: patch_ticket_18338.4.txt added

comment:12 by Areski Belaid, 12 years ago

Cc: areski@… added

Just updated the patch to add some documentation

comment:13 by Tim Graham, 12 years ago

Owner: changed from Lebedev Ilya to Tim Graham

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

comment:14 by Tim Graham <timograham@…>, 12 years ago

Resolution: fixed
Status: assignedclosed

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