Login

reorder apps in admin index

Author:
reanes
Posted:
November 25, 2009
Language:
Python
Version:
1.1
Tags:
admin reorder
Score:
1 (after 1 ratings)

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

  1. Django Admin Index Custom App & Model Ordering by hsc 3 years, 7 months ago
  2. Admin Model Sorting by programmerDan 3 years, 10 months ago
  3. Twin column model admin index by richardbolt 7 years, 3 months ago
  4. Serve static media and indexes from app directories [Python2.5, Development only] by adamlofts 6 years, 10 months ago
  5. View all log entries in the admin by jakub 3 years, 11 months ago

Comments

Please login first before commenting.