Reputation: 73
I was using Python 3.9, Django 3.2.8, and Django-admin-sortable2 1.0.3. I was facing issue that my custom order field (I named it "sort_order") was visible in inline tabular forms but it should have been hidden as per Django-admin-sortable2 implementation. And although I was able to drag-and-drop items, but upon saving the parent object, the sort order wasn't getting saved.
My admin classes were as follows:
from django.forms.models import BaseInlineFormSet
from adminsortable2.admin import CustomInlineFormSet, SortableInlineAdminMixin
class ABCInlineFormSet(BaseInlineFormSet):
...
pass
class ABCAdminInline(SortableInlineAdminMixin, admin.TabularInline):
formset = ABCInlineFormSet
model = models.MyModel
fields = ["your_field"]
...
What worked for me?
Upvotes: 1
Views: 915
Reputation: 73
I found out the hint for this problem in a little unrelated issue here: https://github.com/jrief/django-admin-sortable2/issues/106
I had specified a "formset" in my TabularInline admin class. So, I just tried inheriting my inline formset class with "CustomInlineFormSet" class of django-admin-sortable2. Which solved the problem for me.
from adminsortable2.admin import CustomInlineFormSet, SortableInlineAdminMixin
class ABCInlineFormSet(CustomInlineFormSet, BaseInlineFormSet):
...
pass
class ABCAdminInline(SortableInlineAdminMixin, admin.TabularInline):
formset = ABCInlineFormSet
model = models.MyModel
fields = ["your_field"]
...
Upvotes: 1