B
B
blackbb2015-11-30 22:26:35
Django
blackbb, 2015-11-30 22:26:35

How to reorder objects in django admin?

It is necessary that you can manually change the order of the objects. For example, swap the Black Sea region and Popovka and Storm.
d85d4ea244464b3aa9593e2d6ffaacb4.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2015-12-01
@MAKAPOH

Add an integer priority field to the table in which you manually write the order and sort by this field when displaying this data on the page. If you need to change the order, change the values ​​​​in this field.

A
Artem Afonin, 2015-12-10
@reli

class Town(models.Model):
title = models.CharField(
verbose_name=u'название'.
blank=True, null=True,
max_lenght=255,
)
resorts = models.ForeignKey(
Resorts,
related_name='resort_town',
verbose_name=u'город',
blank=True
)
order = models.PositivIntegerField()

class Meta:
ordering = ['order']
verbose_name = u'страна'
verbose_name_plural = u'страны'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question