Opened 10 years ago

Closed 7 years ago

#12674 closed Bug (fixed)

Admin validation doesn't reflect ModelAdmin's extensibility

Reported by: Honza Král Owned by: Honza Král
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


If you choose to extend ModelAdmin in a non standard way - for example overriding get_changelist, Django still validates it using django.contrib.admin.validation which has no clue on what options are valid for your ModelAdmin class.

By design if you validate something that can be extended/changed/substituted for something it must be either optional (not run whenever you try to access your admin in debug mode) or extensible itself (moved to the classes in question - ModelAdmin, ChangeList etc).

Change History (9)

comment:1 Changed 10 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

comment:2 Changed 10 years ago by Russell Keith-Magee

An example, because it took me a couple of seconds to catch on - imagine you overwrote get_changelist(), and made it use the value in the list_display property of ModelAdmin. However, your revised get_changelist() doesn't use the same format as the stock list_display (e.g., it expects a list of classes, not a list of strings). The ModelAdmin validation will raise an error because list_display doesn't validate to ModelAdmin's default behavior, even though that behaviour isn't necessarily being used.

This might just be a matter of making validate() a method on ModelAdmin that can be overridden like anything else.

comment:3 Changed 9 years ago by Matt McClanahan

Severity: Normal
Type: Bug

comment:4 Changed 8 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 Changed 8 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 Changed 7 years ago by Honza Král

Owner: changed from nobody to Honza Král
Status: newassigned

comment:8 Changed 7 years ago by Russell Keith-Magee

Patch needs improvement: set

I've reviewed this; there's a couple of minor things that I've flagged in the inline comments, but for the most part it looks good.

comment:9 Changed 7 years ago by Honza Kral <honza.kral@…>

Resolution: fixed
Status: assignedclosed

In 4ad1eb1c14b629cf5bcfd253ed40e875f1bddd47:

Fixed #12674 -- provide a way to override admin validation

Moved admin validation code to classes and have those be class
attributes to the ModelAdmin classes.

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