reorder apps in admin index

 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 2 years, 4 months ago
  2. Admin Model Sorting by programmerDan 2 years, 8 months ago
  3. Twin column model admin index by richardbolt 6 years ago
  4. Serve static media and indexes from app directories [Python2.5, Development only] by adamlofts 5 years, 8 months ago
  5. View all log entries in the admin by jakub 2 years, 9 months ago

Comments

(Forgotten your password?)