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
770 stars 181 forks source link

Is SortableStackedInline compatible with django-polymorphic? #386

Closed deanknudsondowner closed 2 months ago

deanknudsondowner commented 8 months ago

Hi ive been trying to get SortableStackedInline working with django-polymorphic and I cant seem to get the moveable boxes working on the inlines. Is this actually possible with this module? I took a look at this closed issue but it didn't end up helping.

models:

class PageObject(PolymorphicModel):
    uuid = models.UUIDField(default=uuid.uuid4, editable=False)
    page = models.ForeignKey(AggregatePage, on_delete=models.CASCADE)
    position = models.PositiveIntegerField(default=0, blank=False, null=False)

    class Meta:
        ordering = ['position']

class CameraPageObject(PageObject):
    camera = models.ForeignKey(Camera, on_delete=models.CASCADE)

class EmbedPageObject(PageObject):
    name = models.CharField(max_length=150, blank=False, null=False)
    url = models.URLField(blank=False, null=False)

admin:

class PageObjectInline(StackedPolymorphicInline):
    class CameraPageObjectInline(StackedPolymorphicInline.Child, SortableStackedInline):
        model = CameraPageObject

    class EmbedPageObjectInline(StackedPolymorphicInline.Child, SortableStackedInline):
        model = EmbedPageObject

    model = PageObject
    child_inlines = [CameraPageObjectInline, EmbedPageObjectInline]

@admin.register(AggregatePage)
class AggregatePageAdmin(SortableAdminBase, PolymorphicInlineSupportMixin, admin.ModelAdmin):
    formfield_overrides = {models.ManyToManyField: {'widget': CheckboxSelectMultiple}}
    inlines = [PageObjectInline]