Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin sort order

i have went through the Poll tutorial on http://docs.djangoproject.com.

I would like to know if it is possible to add a sort order to the 'Choice' Model when editing a Poll and how would i accomplish that

thanks

like image 621
Lylo Avatar asked Dec 31 '10 19:12

Lylo


People also ask

What is admin panel in Django?

Django provides a built-in admin module which can be used to perform CRUD operations on the models. It reads metadata from the model to provide a quick interface where the user can manage the content of the application. This is a built-in module and designed to perform admin related tasks to the user.


2 Answers

class SeminarInline(admin.StackedInline):     model = Seminar     extra = 0     ordering = ('-date',) 

worked for me (above adapted from my model) It sorted in descending date order

like image 120
pbmuk Avatar answered Sep 19 '22 12:09

pbmuk


You can add Meta options to a Django model which can dictate how it behaves. There is an ordering option which defines by which model attribute records should be ordered.

You can find the documentation for the meta ordering option here in the Django docs:

like image 24
Marcus Whybrow Avatar answered Sep 18 '22 12:09

Marcus Whybrow