pythondjangodjango-admindjango-appsdjango-modeladmin

Ordering admin.ModelAdmin objects in Django Admin


Let's say I have my pizza application with Topping and Pizza classes and they show in Django Admin like this:

PizzaApp
-
Toppings      >>>>>>>>>>      Add / Change

Pizzas        >>>>>>>>>>      Add / Change

But I want them like this:

PizzaApp
-
Pizzas        >>>>>>>>>>      Add / Change

Toppings      >>>>>>>>>>      Add / Change

How do I configure that in my admin.py?


Solution

  • This is actually covered at the very bottom of Writing your first Django app, part 7.

    Here's the relevant section:

    Customize the admin index page

    On a similar note, you might want to customize the look and feel of the Django admin index page.

    By default, it displays all the apps in INSTALLED_APPS that have been registered with the admin application, in alphabetical order. You may want to make significant changes to the layout. After all, the index is probably the most important page of the admin, and it should be easy to use.

    The template to customize is admin/index.html. (Do the same as with admin/base_site.html in the previous section -- copy it from the default directory to your custom template directory.) Edit the file, and you'll see it uses a template variable called app_list. That variable contains every installed Django app. Instead of using that, you can hard-code links to object-specific admin pages in whatever way you think is best.