Opened 9 years ago

Last modified 8 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


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.

Change History (6)

comment:1 Changed 9 years ago by mariarchi

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 9 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

comment:3 Changed 9 years ago by Russell Keith-Magee

Component: Contrib appsdjango.contrib.admin

comment:4 Changed 8 years ago by Matt McClanahan

Severity: Normal
Type: Bug

comment:5 Changed 8 years ago by Julien Phalip

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 7 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

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