0

I am attempting to build a model that will keep items in order when a user changes its position (this happens on a JS frontend).

I feel a 'float' is best, as this value will constantly be changing. I will be passing the value by a javascript application.

class Item(models.Model):
    title = models.CharField("Title", max_length=10000, blank=True)
    position = models.FloatField("Item position", blank=True, null=True)

So the data could be (super simplified example):

title       |     position
Charlie     |     1
Mark        |     2
Bruce       |     3

When Mark's position changes, it would automatically change Charlies' to position value to 2:

title       |     position
Charlie     |     2
Mark        |     1
Bruce       |     3

How would I post this information (API) so that django realises one title belongs above another?

Ycon
  • 1,830
  • 3
  • 27
  • 56
  • Possible duplicate of [Making changes to multiple records based on change of single record with SQL](http://stackoverflow.com/questions/40623132/making-changes-to-multiple-records-based-on-change-of-single-record-with-sql) – e4c5 Mar 22 '17 at 05:04
  • Languages maybe different but the idea is the same – e4c5 Mar 22 '17 at 05:04
  • I understand the idea, but I want it in my language (python/django). Can someone provide an example? – Ycon Mar 22 '17 at 09:51

0 Answers0