- Author:
- programmerDan
- Posted:
- August 8, 2011
- Language:
- Python
- Version:
- 1.2
- Score:
- 1 (after 1 ratings)
This allows you to order the models on the index page of the administration site in a custom way.
This modification goes in the index method of django.contrib.admin.sites.AdminSite. I personally monkey patched it in where my models are loaded and registered with the admin site. Be careful that if you add new models you update the sorting dictionary, else you will get a key error. If no sorting is defined for an app, it will default to alphabetical order.
Note that you'll probably want to also insert this into the app_index function as well.
If you like my work, please check out my employer's site at 829llc.com - Dan
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
- Form field with fixed value by roam 3 days, 20 hours ago
- New Snippet! by Antoliny0919 1 week, 3 days ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 2 months, 4 weeks ago
- get_object_or_none by azwdevops 6 months, 3 weeks ago
- Mask sensitive data from logger by agusmakmun 8 months, 2 weeks ago
Comments
Please login first before commenting.