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

SortableInlineAdminMixin does not work after 2.0 #304

Closed michelematera closed 2 years ago

michelematera commented 2 years ago

After updating to 2.0, the drag and drop button no longer appears in TabularInline. Downgrading to 1.0.4 everything works fine.

class PageLinkInline(SortableInlineAdminMixin, admin.TabularInline):
    model = models.PageLink
    extra = 0
    fk_name = 'page'
    raw_id_fields = ['page_child']
    ordering = ['position']

I am using Django==4.0.3.

jrief commented 2 years ago

Please read how to report bugs.

After that, if you point the browser on http://localhost:8000/admin/testapp/sortablebook3/17/change/ you get a demo with a TabularInline.

Please report bugs based on that demo.

michelematera commented 2 years ago

The bug occurs when SortableBookAdmin does not inherit SortableAdminMixin. In this case I am unable to sort UnorderedSortableBookAdmin.

jrief commented 2 years ago

fixed in version 2.0.3

michelematera commented 2 years ago

The bug was not fixed. Up to version 1.0.4 it was not necessary to inherit SortableAdminMixin to SortableBookAdmin to sort the inlines. This is a big limitation.

jrief commented 2 years ago

The parent admin class now must inherit from SortableAdminBase in order to make inlines sortable. The alternative would be to override the templates, something I definitely do not want to do. Why is that a big limitation for you?

https://github.com/jrief/django-admin-sortable2/blob/master/docs/source/usage.rst#in-djangos-admin-detail-view-make-stacked--and-tabular-inlines-sortable

michelematera commented 2 years ago

Forgive me, I hadn't read about SortableAdminBase. Actually from my point of view it would be more convenient to insert everything in SortableInlineAdminMixin as initially there was up to 1.0.4 but that's okay too. Thanks

jrief commented 2 years ago

Actually from my point of view it would be more convenient to insert everything in SortableInlineAdminMixin as initially there was up to 1.0.4

yes, that would be nice. Unfortunately the API designed around Django-4.0 doesn't offer this out of the box. The alternative would have been to continue overriding templates tabular.html and stacked.html as required until version 1.0.4.

I hope you agree, that the current solution is less error-prone and future-safe.