I have the following table 'book':
id shelf position (on shelf)
1 2 3
2 1 1
3 1 2
4 2 2
5 2 1
I need to move book4 to the end of shelf 1, therefore I need to set book4 position to [max(position) where shelf=1] + 1 and position where position=[max(position) where shelf=2] to book4 initial position (to close the gap)
I tried this, but Max doesn't seem to work this way...
Book.objects.filter(shelf=2).annotate(max_position_on_shelf=Max('position'))\
.filter(position=F('max_position_on_shelf'))\
.update(position=F('max_position_on_shelf') + 1)
Do it more simple:
This would allow you to move a book to any position