{{{#!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.
* 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>
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>
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>
* 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>