Opened 8 years ago

Closed 4 years ago

#15571 closed New feature (wontfix)

AdminSite index and app_index methods could include the model_admin in the model_dict

Reported by: Batiste Bieler Owned by: nobody
Component: contrib.admin Version: 1.2
Severity: Normal Keywords: admin, AdminSite, model_admin
Cc: sverrejoh Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When sub-classing the "index.html" template for the admin interface, I wanted to show or hide some models (without disabling them, ie: still reachable in the admin as usual).

The model_dict doesn't contain the model_admin, so I needed to subclass the index method just to add this line:

model_dict = {
    'name': capfirst(model._meta.verbose_name_plural),
    'admin_url': mark_safe('%s/%s/' % (app_label, model.__name__.lower())),
    'perms': perms,
    'model_admin': model_admin, # added just this line

Then I can add some attribute "index_hide" to my ModelAdmin, and use it in my subclassed index.html to decide what to show.

Would it be a good idea to add this line to the admin, even if there is no use in the original template?

I believe it reflect some kind of common use-case. The need to access the model_admin within the index template seems natural to me.

Change History (7)

comment:1 Changed 8 years ago by sverrejoh

Cc: sverrejoh added

comment:2 Changed 8 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

comment:3 Changed 8 years ago by Luke Plant

Type: New feature

comment:4 Changed 8 years ago by Luke Plant

Severity: Normal

comment:5 Changed 7 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 Changed 7 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:7 Changed 4 years ago by Aymeric Augustin

Resolution: wontfix
Status: newclosed

This effect is usually achieved by permissions. Staff users only see models they're allowed to edit.

Super users may have a crowded index but they should be sufficiently computer-literate to use Ctrl-F.

Considering the lack of interest during the last three years, I don't think the problem is that common in practice, and I'll close the ticket.

Feel free to start a discussion on the django-developers mailing-list if I missed something.

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