Code

Opened 4 years ago

Last modified 3 years ago

#12679 new Bug

In admin, inlines should be allowed to be properties

Reported by: mariarchi Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords: admin inlines duck typing
Cc: admin@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, if admin class defines an attribute 'inlines' which is not an instance of tuple or a list, django will raise an error.
I believe that this is wrong and contradicts the duck typing philosophy - we shouldn't care that the attribute 'inlines' is an instance of list/tuple, but rather we should care that it is iterable.

The reason why I believe that behavior is wrong is the following:
one might want to define 'inlines' as a property. This might happen when admin class A inherits from admin class B, and class B adds some inlines (that can be useful when developing a pluggable application). If class A has some inlines of its own, it can be useful to declare inlines as a property and then call 'super' to retrieve the inlines of class B.

Attachments (0)

Change History (6)

comment:1 Changed 4 years ago by mariarchi

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Anyway, that behavior is quite inconsistent with the fact that for most attributes in model/admin/url definition django does not check the instance of said attribute

comment:2 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 4 years ago by russellm

  • Component changed from Contrib apps to django.contrib.admin

comment:4 Changed 3 years ago by mattmcc

  • Severity set to Normal
  • Type set to Bug

comment:5 Changed 3 years ago by julien

  • Easy pickings unset

Currently a lot of ModelAdmin's attributes (list_display, readonly_fields, list_filter, etc.) are expected to be lists or tuples. ModelAdmin.inlines shouldn't be treated as a special case. If we allow it to be merely an iterable, then the same should be done for all those other attributes. (Hint: check out django.contrib.admin.validation.check_isseq())

See also #16089 which is looking at adding flexibility with inlines registration.

comment:6 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.