[Django] #24746: Add support for excluding callables in child ModelAdmin defined in its super

12 views
Skip to first unread message

Django

unread,
May 4, 2015, 9:43:57 AM5/4/15
to django-...@googlegroups.com
#24746: Add support for excluding callables in child ModelAdmin defined in its
super
---------------------------------+--------------------
Reporter: giuliettamasina | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
If I have a super `ModelAdmin` class that defines `list_display` with some
callable, there is no obvious way to have this callable in the `exclude`
attribute in subclasses of the same `ModelAdmin`. See example:

{{{#!python
class ParentAdmin(admin.ModelAdmin):
def my_callable(obj):
# Some custom stuff here.
return obj

list_display = ('name', 'description', my_callable)

class ChildAdmin(admin.ModelAdmin):
exclude = ('description',) # I want to exclude my_callable but I
can't!
}}}

I currently achieve this through weird hacks such as filtering the parent
attribute to exclude items with a certain func_name, etc.

Or am I missing something obvious?

--
Ticket URL: <https://code.djangoproject.com/ticket/24746>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 4, 2015, 9:45:06 AM5/4/15
to django-...@googlegroups.com
#24746: Add support for excluding callables in child ModelAdmin defined in its
super
---------------------------------+--------------------------------------

Reporter: giuliettamasina | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by giuliettamasina):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Note that in my example I could just redefine `list_display`, but in my
actual use case there are several levels of inheritance of which I want to
exclude some things from some levels.

--
Ticket URL: <https://code.djangoproject.com/ticket/24746#comment:1>

Django

unread,
May 4, 2015, 11:03:32 AM5/4/15
to django-...@googlegroups.com
#24746: Add support for excluding callables in child ModelAdmin defined in its
super
---------------------------------+--------------------------------------

Reporter: giuliettamasina | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by timgraham):

If you need dynamic values, I think it would be easier to use the method
versions like `get_list_display()`. Will that work for you?

By the way, my understanding is that `exclude` affects the model form, not
the values in the changelist (`list_display`).

--
Ticket URL: <https://code.djangoproject.com/ticket/24746#comment:2>

Django

unread,
May 4, 2015, 11:38:33 AM5/4/15
to django-...@googlegroups.com
#24746: Add support for excluding callables in child ModelAdmin defined in its
super
---------------------------------+--------------------------------------

Reporter: giuliettamasina | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by giuliettamasina):

Yes, you are right, it was only in my confused mind that `exclude` affects
`list_display` as well.

Using `get_*()` makes code cleaner, but I still wish there was some simple
way to subtract from `list_display` by just setting an attribute on the
model admin class. Worth opening another ticket?

--
Ticket URL: <https://code.djangoproject.com/ticket/24746#comment:3>

Django

unread,
May 4, 2015, 12:43:23 PM5/4/15
to django-...@googlegroups.com
#24746: Add support for excluding callables in child ModelAdmin defined in its
super
---------------------------------+--------------------------------------
Reporter: giuliettamasina | Owner: nobody
Type: Uncategorized | Status: closed
Component: contrib.admin | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => wontfix


Comment:

I don't think adding another customization hook for your use case will
make things simpler in the long run (to make the API consistent, we might
need to add a similar flag for many other ModelAdmin attributes). The
function-based hooks were added so that we don't have to try to support
every use case with simple attributes. You can raise the issue on the
DevelopersMailingList if you like, but that's my perspective.

--
Ticket URL: <https://code.djangoproject.com/ticket/24746#comment:4>

Reply all
Reply to author
Forward
0 new messages