Opened 5 years ago

Closed 23 months ago

#12674 closed Bug (fixed)

Admin validation doesn't reflect ModelAdmin's extensibility

Reported by: Honza_Kral Owned by: Honza_Kral
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

Description

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 5 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 5 years ago by russellm

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 4 years ago by mattmcc

  • Severity set to Normal
  • Type set to Bug

comment:4 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:5 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:6 Changed 2 years ago by Honza_Kral

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

comment:8 Changed 23 months ago by russellm

  • 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 23 months ago by Honza Kral <honza.kral@…>

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

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