Some potential bugs found when making custom admin pages

When preparing custom admin pages for an upcoming presentation, I found some inconsistencies in the admin.

One has already been picked up; I’d like some confirmation if the other items are bugs or intentional.

NB. Feel free to create Trac issues for these items if desired and post them in the comments, or I will do so later.

  1. Python—Most admin pages require model._meta to set opts; calling underscore functions is undesirable. Should there be a non-underscore function to retrieve these?
  2. Python—Missing variable module in some views (e.g., model history view has it, change form doesn’t). Especially noticable in the breadcrumbs block.
  3. CSS—Missing padding for ol in base.css (near line 654), selector .module p, .module ul, .module h3, .module h4, .module dl, .module pre.
  4. (No confirmation needed): #37332 (Admin list_display does not show icon for generated boolean fields).

Related code:

(Applies to other admin templates as well.)

My examples:

1 Like

The _meta attribute was intended to be an internal API, but has shown itself to be extremely useful as a public attribute. It is a well-known exception to the Django attribute naming convention, and is so well-entrenched at this point that it is highly unlikely to ever be changed.

You can redefine it yourself in your applications, but I’d be very surprised to see it become a core change. (Just adding an alias runs the risk of creating conflicts with other packages that already use that name for their own purposes.)

1 Like

Yeah.It was formalized as public API in Django 1.8: Django 1.8 release notes | Django documentation | Django . Maybe we can interpret the “private” underscore prefix more as “you don’t normally need this, but if you do it’s here…”.

What’s the impact? The breadcrumbs don’t render correctly?

Anyway, nice one spotting these, making a list, finding the exsisting issue, making this post, and any future issues/fixes you submit! Cheers!

1 Like

It’s mostly an inconsistency that can break custom templates when copying from Django’s templates.

See the difference of these URLs to the model list view, usually the third breadcrumb item (search for <a href="{% url opts|admin_urlname:'changelist' %}">).

  1. Object history template: {{ module_name }}.
  2. Change form template: {{ opts.verbose_name_plural|capfirst }}.

I created a ticket for the module_name issue: #37399 (Include module_name in all model admin views with breadcrumbs) – Django.