R
R
RabbitRun92021-08-09 13:21:06
Django
RabbitRun9, 2021-08-09 13:21:06

How to move Posts up and down in Django?

There was a problem with the implementation of the ability to move posts - higher, lower. Django project. From everything that I googled, there are implementations on Vue, React, etc. But it is the implementation of such a movement on Django that is of interest, even if it is with reloading the entire page - but without much intervention of additional libraries.
Maybe someone did, tell me or give me an idea. All helpful answers will be marked as correct.
PS: According to the implementation, I myself guess that you need an additional field in the Order type Model and assign an index to it and change it when sorting. But how to actually implement this, from which side to approach, was a little lost.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alternativshik, 2021-08-09
@RabbitRun9

As simple as possible:
in the Post model, add the field Integer ordering = models.IntegetField(default=0)
in the Meta of the model, add: ordering = ['ordering']
In the Admin panel, put down the necessary order in the ordering fields.
...
Profit.

A
akrvch, 2021-08-22
@akrvch

You can do as alternativshik says , but better store ordering in sessions so that each user can set their own display order.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question