Exposing custom views in admin index page

82 views
Skip to first unread message

mrts

unread,
Mar 6, 2019, 6:40:06 AM3/6/19
to Django developers (Contributions to Django itself)
Hello!

Django ModelAdmin class has a nice way to create custom admin views with get_urls(). What is missing however is a way to expose them in the admin index page.

Frank Wiles created the (now abandoned) django-admin-views package [1] as a workaround and there are many questions regarding this in StackOverflow [2][3][4][5].

What do you think about exposing custom views in admin index page via a new ModelAdmin.extra_views attribute?
extra_views would be a list of dictionaries/objects with 'url' and 'name' fields.

They would be visible in the index page with the following change to django/contrib/admin/templates/admin/index.html:

--- ../venv/Lib/site-packages/django/contrib/admin/templates/admin/index.html   2019-02-28 01:22:12.767388100 +0200
+++ templates/admin/index.html  2019-03-06 12:57:22.070586600 +0200
@@ -43,6 +43,15 @@
                 <td>&nbsp;</td>
             {% endif %}
             </tr>
+            {% if model.extra_views %}
+              {% for view in model.extra_views %}
+            <tr>
+                <th scope="row"><a href="{{ view.url }}">{{ view.name }}</a></th>
+                <td>&nbsp;</td>
+                <td>&nbsp;</td>
+            </tr>
+              {% endfor %}
+            {% endif %}
         {% endfor %}
         </table>
         </div>

Best regards,
Mart

---

Kye Russell

unread,
Mar 6, 2019, 7:12:02 AM3/6/19
to django-d...@googlegroups.com
I understand that overly extending the admin interface is a common anti pattern, but this still feels within reason to me. Extending the admin interface in this way has for me personally felt like a bit of a black box. 

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/2f99993c-7078-4bc7-b62d-7cf66acc3bec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carlton Gibson

unread,
Mar 6, 2019, 9:45:24 AM3/6/19
to Django developers (Contributions to Django itself)
django-admin-views was functional as recently as Django 2.0 https://github.com/frankwiles/django-admin-views/issues/34

I'm guessing it would be pretty easy to pick up. (Frank stated he was very happy for someone to become steward...) 

(I appreciate that doesn't address the "should we have this in core?" question.) 

mrts

unread,
Mar 9, 2019, 7:49:27 AM3/9/19
to Django developers (Contributions to Django itself)
Fair enough, this seems not to pick up steam - let it be then.

For the record, the workaround is to add views to the admin site using a proxy model and a model admin class with custom changelist_view(), removing add, change and delete permissions so that only view permission remains. It will be listed in the admin index page with view-only icon 👁, so the result is decent enough.

(Here's a detailed explanation: https://stackoverflow.com/a/54974566/258772 ).

Note that django-admin-views is not compatible with Django 2.1.

Best regards,
Mart

Carlton Gibson

unread,
Mar 9, 2019, 8:05:24 AM3/9/19
to Django developers (Contributions to Django itself)
Just an aside on this, after the ORM, the admin has the second highest number of open accepted tickets. If we could bring that down, adding features would be cool, but it's a bit "Gulp" at the moment, if you take my meaning. 

> Note that django-admin-views is not compatible with Django 2.1.

Are the errors not addressable — 2 to 2.1 isn't the world's biggest change is it? (Probably a discussion for the repo...) 
C. 
Reply all
Reply to author
Forward
0 new messages