jrief / django-admin-sortable2

Generic drag-and-drop ordering for objects in the Django admin interface
https://django-admin-sortable2.readthedocs.io/en/latest/
Other
753 stars 179 forks source link

Inheritance model doesn't update sort. #329

Open portedison opened 2 years ago

portedison commented 2 years ago

With inheritance, e.g. Writing, Event, etc all inheriting from Content. Creating Writing doesn't trigger (or implement) the admin mixin applied to the Content model. They add with the default value '0'. And subsequently can't be updated, as there are too many with the value of '0'. How should we trigger this to resort (similar to the management command) after save?

class Content(models.Model):
      sort_order = models.PositiveIntegerField(default=0, db_index=True)
      ...

class Writing(Content):
      ....
portedison commented 2 years ago

Is this the idea of PolymorphicSortableAdminMixin- https://github.com/jrief/django-admin-sortable2/blob/3c7c8c34a07c8d522d8f6c5216f0e0a6180730a9/adminsortable2/admin.py#L419

jrief commented 2 years ago

Could you please fork the project and create a polymorphic model where this problem occurs. For instance by separating Book from Magazin (a magazin doesn't have an author but a publisher). I then can look for a solution and use that as a starting point to implement a unit test.