django-nested-admin
django-nested-admin copied to clipboard
Drag and drop sorting with polymorphic models without any nesting always sets beyondMaxLevels too large
I have the following example code for the admin interface:
class ClassInline(nested_admin.NestedStackedPolymorphicInline):
class SomeClassInline(nested_admin.NestedStackedPolymorphicInline.Child):
model = SomeClass
# [...] other elements of NestedStackedPolymorphicInline.Child
model = BaseClass
child_inlines = [
SomeClassInline #, [...]
]
sortable_field_name = 'order'
class ClassLevelAdmin(nested_admin.NestedPolymorphicModelAdmin, admin.ModelAdmin):
model = ClassLevel
inlines = [
ClassInline,
]
list_display = [
'name',
]
admin.site.register(ClassLevel, ClassLevelAdmin)
When I want to sort inlines via drag and drop in the admin interface the following happens:
- The background of the inline has a red background and the element in the DOM has the error class "ui-nestedSortable-error"
- This happens immediately when clicking on the inline without moving it between other inlines
- Moving the inline between other inlines does not work and it will be moved back to the starting position
- The
this.beyondMaxLevelsvariable (in the Javascript code) is set to 1. This should probably be always 0 in this case as there is only a flat hierarchy of inlines and my guess is a problem with the calculation of the levels
Another admin interface for another model with a nested polymorphic inline works:
class ClassInline(nested_admin.NestedStackedPolymorphicInline):
class SomeClassInline(nested_admin.NestedStackedPolymorphicInline.Child):
model = SomeClass
inlines = [SomeNestedInline, ]
It would be nice if the sorting feature of django-nested-admin could work without any nested inlines as it also supports django-polymorphic. Thank you for your module!
- Django 2.2.13
- Django Nested Admin 3.3.1
- Firefox and Chrome used in the admin interface
I've tried several different variations on your example code and am unable to reproduce this. Could you provide a test repo (or even just a functional models.py and admin.py) that I could use to troubleshoot this?