Is there any efficient algorithm for updating ordered data in DRF?

44 views Asked by At

I had a problem with algorithm which updates ordered data.

For example, I have one model called Route.

class Route(models.Model):
   order = models.IntegerField(null=False, blank=False)
   memo = models.CharField(max_length=400, null=True, blank=True)

I have Route ordered data such as... (doesn't fit in the grammar)

(id:1, order:1, memo:"aaa")->(id:2, order:2, memo:"bbb")->(id:3, order:3, memo:"ccc")

And user can change, delete, add to the order in one endpoint, such as...

(order:3)->(order:1)->(order:2) # change order
(order:1)->(order:3)  # delete elements (order:2)
(order:1)->(order:2)->(order:3)->(order:4)  # add elements

At first, I thought that I can remove all these existing data and recreate incoming data. (I know it's really inefficient, but I decided to do this.)

But I have problem with preserving memo data among the data that have not been added or deleted.

What should I do?

0

There are 0 answers