Order items with django-admin interface

Let's say that I have a django model that looks like this:

class question(models.Model): order = models.IntegerField('Position') question = models.CharField(max_length= 400) answer = models.TextField() published = models.BooleanField() def __unicode__(self): return self.question 

In my opinion, I show all the questions sorted in ascending order field.

My question is: is there an easy way to change the order field in the django admin interface? Right now I have to go to edit the question, than to see which number to put in the order field, and maybe even reorder all the other elements. What I really want will be up and down on the admin page, where all the questions are listed.

Is it possible?

+8
django django-models django-admin
source share
4 answers

Of course, here is an example admin.py file with up and down links for changing the order of elements: https://github.com/alexvasi/django-simplemenu/blob/master/simplemenu/admin.py

Basically, you just need to override the get_urls method to add your custom views ( move_up and move_down in this example).

A better known example is django-treemenus , but there is additional code to support older versions of django.

+5
source share

Check this out: django-orderedmodel .

This is a really simple implementation of an abstract base class for elements that can be ordered using the admin interface. No external dependencies and easy to use.

+12
source share

If someone is looking for a solution to this problem in 2017, I found a great Django Admin Sortable package

0
source share

Source: https://habr.com/ru/post/651283/


All Articles