使 django-admin-sortable 和 django-parler 一起工作

Make django-admin-sortable and django-parler work together

我有两个具有多对多关系的模型,使用 through table

# models.py

class Item(TranslatableModel):
    name = models.CharField(max_length=100)  # this one is translatable

class Person(TranslatableModel):
    name = models.CharField(max_length=100)  # this one is translatable
    items = models.ManyToManyField(
        'Item',
        through='PersonItem',
    )


class PersonItem(Sortable):

    class Meta(Sortable.Meta):
        ordering = ['order']

    person = models.ForeignKey('Person')
    item = SortableForeignKey('Item')

但我无法在管理

中对 Item 进行排序
# admin.py

class PersonItemInline(TranslatableTabularInline, SortableTabularInline):
    model = PersonItem
    form = PersonItemForm
    extra = 1

class PersonAdmin(TranslatableAdmin):
    form = PersonForm
    inlines = [
        PersonItemInline
    ]


admin.site.register(Person, PersonAdmin)

当我首先从 translatable 继承时,我失去了排序功能。当我首先尝试从 sortable 继承时,出现以下错误

NoReverseMatch Reverse for 'person_person_do_sorting' with arguments '(239,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

环境 (python 3): django==1.10.7django-parler==1.6.5django-admin-sortable==2.0.19

@most-wanted 确保继承顺序正确:

class PersonItemInline(SortableTabularInline, TranslatableTabularInline):
    ...
class PersonAdmin(SortableAdmin, TranslatableAdmin):
    ...

并覆盖 PersonAdmin class 中的 change_form_template_extends,如下所示:

class PersonAdmin(SortableAdmin, TranslatableAdmin):
    change_form_template_extends = 'admin/parler/change_form.html'