Closed pabu closed 2 years ago
Oh and a temporary fix if you end up in this situation is to just fire off a SQL query where you for instance set your sorting column value to your id for all rows. Provided that you have a numeric id for you object of course.
Thanks!
Problem:
Documentation suggests defining a sort weight column as:
my_order = models.PositiveIntegerField(default=0, blank=False, null=False)
Any existing objects in the database will thus all have the same value of zero for my_order after migration.
Since the sorting functionality seems to be based on swapping weights of existing objects rather than assigning new weights this effectively makes objects with the same assigned weights un-sortable.
Also note that creating a new object from the Django admin with django-admin-sortable2 enabled will set my_order to a non zero value - overriding the default model value of zero. So the part of the documentation that states the importance of my_order’s default value to be 0 would only apply for objects that already exist which is also the case for which it breaks.
To reproduce:
Create a few instances of the model suggested in the documentation without django-admin-sortable2 enabled. Enable django-admin-sortable2 and observe how dragging models in the admin list view has no effect.