A quick & dirty way of sorting the apps on the admin index page however you want. It requires you to override the default admin/index.html template. The instructions are in the docstring, they assume you insert the code above in a templatetag file called admin_app_order.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | from django.conf import settings
from django import template
register = template.Library()
def reorder_admin_apps(app_list):
"""
This will reorder the apps in the admin using weights defined in the RHEC_ADMIN_APP_WEIGHTS dict.
The names, unfortunately, must be the verbose names displayed in the admin, not the actual app name,
because that is what is in the admin app_list var.
The app_list argument object is modified, it does not return a value.
Usage: Define your app weights in settings.py like so:
RHEC_ADMIN_APP_WEIGHTS = {'Sites': 1,
'Auth' : 2}
Override the default admin index.html template and insert the following before the app_list is rendered:
{% load admin_app_order %}{% reorder_admin_apps app_list %}
"""
weights = getattr(settings, 'RHEC_ADMIN_APP_WEIGHTS', {})
for app_dict in app_list:
app_dict['rhec_sort_weight'] = weights.get(app_dict['name'], 999)
app_list.sort(lambda x, y: cmp(x['rhec_sort_weight'], y['rhec_sort_weight']))
return ''
register.simple_tag(reorder_admin_apps)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Please login first before commenting.