Admin Model Sorting

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Each key in this dictionary corresponds to our application's url, including trailing slash.
# The value of each entry is a list of URLs of our models, in the order we would like them to be displayed.
modelOrder = {}
modelOrder['agentAccess/'] = ['agentAccess/post/', 'agentAccess/post_category/', 'agentAccess/page/', 'agentAccess/page_category/', 'agentAccess/fileupload/']

# Check if we have a corresponding ordering list, if not, sort by name.
for app in app_list:
    if modelOrder.get(app['app_url'], None):
        app['models'].sort(lambda x, y: cmp(modelOrder[app['app_url']].index(x['admin_url']), modelOrder[app['app_url']].index(y['admin_url'])))
    else:
        app['models'].sort(lambda x, y: cmp(x['name'], y['name']))

More like this

  1. Ordering Models in Django Site administration screen by btbytes 5 years, 10 months ago
  2. Django Admin Index Custom App & Model Ordering by hsc 1 year, 6 months ago
  3. App Display Label Template Filter Workaround by programmerDan 1 year, 9 months ago
  4. Admin App/Model Custom Ordering by stephen_mcd 3 years, 3 months ago
  5. reorder apps in admin index by reanes 3 years, 6 months ago

Comments

(Forgotten your password?)