Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin UI does not get added #374

Open
lsmith77 opened this issue Sep 1, 2023 · 1 comment
Open

Admin UI does not get added #374

lsmith77 opened this issue Sep 1, 2023 · 1 comment

Comments

@lsmith77
Copy link

lsmith77 commented Sep 1, 2023

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.

@lsmith77
Copy link
Author

lsmith77 commented Sep 1, 2023

might be a duplicate of #372

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant