R
R
RabbitRun92021-08-12 17:10:00
Django
RabbitRun9, 2021-08-12 17:10:00

Alternative sorting on Django?

Hello.
Need help.

Briefly about the project. A typical django news site where each news item is sorted by release date.

It is necessary to implement the possibility of alternative sorting, not by date, but with the ability to raise one news item higher than another, or lower it by one item lower.
On the main page, not in the admin panel.

From my ideas and thoughts: in the Model, add the field ordering = models.PositiveIntegerField() , and so that when adding each news, the index (ordering) is hidden in this field , type in order, by the function - "Total number of indexes" + 1. And then, when you click on the down arrow (on the news itself)the news moves lower, swapping the indexes with the underlying news.
Here is an idea for such sorting.

Does anyone have any better ideas?? Or maybe someone has already encountered and made a similar implementation to change the order of displaying the News ??
Any advice, any help is welcome. Don't be indifferent.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cython, 2021-08-13
@cython

You can try adding a priority_offset(IntegerField) field for each news item. On the page, sort the news by news id + priority_offset. As a result, the news will be sorted by age and your priority.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question