Ordering admin.ModelAdmin objects
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?
A workaround that you can try is tweaking your models.py as follows:
class Topping(models.Model):
.
.
.
class Meta:
verbose_name_plural = "2. Toppings"
class Pizza(models.Model):
.
.
.
class Meta:
verbose_name_plural = "1. Pizzas"
Not sure if it is against the django's best practices but it works (tested with django trunk).
Good luck!
PS: sorry if this answer was posted too late but it can help others in future similar situations.
If you want to solve this in 10 seconds just use spaces in verbose_name_plural, for example:
class Topping(models.Model):
class Meta:
verbose_name_plural = " Toppings" # 2 spaces
class Pizza(models.Model):
class Meta:
verbose_name_plural = " Pizzas" # 1 space
Of course it isn't ellegant but may work for a while before we get a better solution.
I eventually managed to do it thanks to this Django snippet, you just need to be aware of the ADMIN_REORDER
setting:
ADMIN_REORDER = (
('app1', ('App1Model1', 'App1Model2', 'App1Model3')),
('app2', ('App2Model1', 'App2Model2')),
)
app1
must not be prefixed with the project name, i.e. use app1
instead of mysite.app1
.