Code

Opened 3 years ago

Closed 5 weeks ago

#15571 closed New feature (wontfix)

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

Reported by: batiste 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

Description

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.

Attachments (0)

Change History (7)

comment:1 Changed 3 years ago by sverrejoh

  • Cc sverrejoh added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 3 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 3 years ago by lukeplant

  • Type set to New feature

comment:4 Changed 3 years ago by lukeplant

  • Severity set to Normal

comment:5 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:6 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:7 Changed 5 weeks ago by aaugustin

  • Resolution set to wontfix
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


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

 
Note: See TracTickets for help on using tickets.