jrief/django-admin-sortable2

Admin UI does not get added

lsmith77 opened this issue · 1 comments

django-admin-sortable2==2.1.9
django-debug-toolbar==4.2.0
  - django [required: >=3.2.4, installed: 4.2.4]
django-enum==1.2.1
django-import-export==3.2.0

A rule can have multiple sorted alternatives (one to many) and multiple sorted dimensions (many to many).

from django.db import models

class Dimension(models.Model):
    name = models.CharField(max_length=255, unique=True)

class Rule(models.Model):
    name = models.CharField(max_length=255, unique=True)

    dimensions = models.ManyToManyField(Dimension, through='RuleDimension')

class RuleDimension(models.Model):
    class Meta:
        ordering = ('ordering', )
        unique_together = (("rule", "dimension"),)

    ordering = models.PositiveIntegerField(default=0, null=False, blank=False)

    rule = models.ForeignKey(Rule, on_delete=models.CASCADE)
    dimension = models.ForeignKey(Dimension, on_delete=models.CASCADE)

class Alternative(models.Model):
    class Meta:
        ordering = ('ordering',)

    name = models.CharField(max_length=255, unique=True)

    rule = models.ForeignKey(Rule, on_delete=models.CASCADE)

    ordering = models.PositiveIntegerField(default=0, null=False, blank=False)

Now I want to manage the rule while being able to manage the alternatives inline as well as the dimension mappings.

from .models import Rule, Alternative, Dimension
from adminsortable2.admin import SortableAdminBase, SortableTabularInline, SortableStackedInline

@admin.register(Alternative)
class AlternativeAdmin(admin.ModelAdmin):
    class Meta:
        model = Alternative

# or SortableTabularInline
class AlternativeInline(SortableStackedInline):
    model = Alternative

# or SortableTabularInline
class DimensionInline(SortableStackedInline):
    model = Rule.dimensions.through

@admin.register(Dimension)
class DimensionAdmin(admin.ModelAdmin):
    resource_class = DimensionResource

    class Meta:
        model = Dimension

@admin.register(Rule)
class RuleAdmin(SortableAdminBase, admin.ModelAdmin):
    class Meta:
        model = Rule

However on http://127.0.0.1:8000/admin/rules/rule/add/ I do not see any of the UI elements to re-order (up/down buttons or drag&drop). jQuery, sortable.css ect seem to be loaded.

might be a duplicate of #372