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

SortableInlineAdminMixin does not work with nested_admin NestedTabularInline #286

Open
smipi1 opened this issue Oct 3, 2021 · 2 comments

Comments

@smipi1
Copy link

smipi1 commented Oct 3, 2021

I have tried creating a doubly-nested sorted inline admin using:

from django.contrib import admin
from translated_fields import TranslatedFieldAdmin
from nested_admin import NestedStackedInline
from adminsortable2.admin import SortableInlineAdminMixin

class LineInline(TranslatedFieldAdmin, SortableInlineAdminMixin, NestedTabularInline):
    model = Line
    extra = 0

class StanzaInline(TranslatedFieldAdmin, SortableInlineAdminMixin, NestedTabularInline):
    model = Stanza
    inlines = [
        LineInline,
    ]
    extra = 0

@admin.register(Poem)
class PoemAdmin(TranslatedFieldAdmin, NestedModelAdmin):
    inlines = [
        StanzaInline,
    ]

adminsortable2 throws an ImproperlyConfigured error (and rightfully so):

Class poems.admin.<class 'poems.admin.StanzaInline'> must also derive from admin.TabularInline or admin.StackedInline

nested_admin derives NestedTabularInline from InlineModelAdmin as can be seen here.

It appears that inheriting both the django and nested_admin classes prevents the adminsortable2 exception, but this breaks the nested admin inlines in the admin page:

class LineInline(TranslatedFieldAdmin, SortableInlineAdminMixin, NestedTabularInline, admin.TabularInline):
...
class StanzaInline(TranslatedFieldAdmin, SortableInlineAdminMixin, NestedTabularInline, admin.TabularInline):

Figuring out exactly how to work around this is way above my experience and skill, but I am very eager to assist in any way I can.

Is there a way to get the django-nested-admin and django-admin-sortable2 plugins to work together?

I'm using:

Django==3.2.3
django-admin-sortable2==1.0.2
django-nested-admin==3.3.3
django-translated-fields==0.11.2
@smipi1
Copy link
Author

smipi1 commented Oct 3, 2021

I also logged an issue with the django-nested-admin project so that both projects are aware of the incompatibility.

@jrief
Copy link
Owner

jrief commented Oct 5, 2021

I never worked with django-nested-admin, so I can't really drill down on the problem.
Here is my hint on how to solve it: If you somehow can find out if your for is a NestedTabularInline, than I assume that you have to provide a special template for it. Use that template as a starting point with the additional sortable features and return it in https://github.com/jrief/django-admin-sortable2/blob/master/adminsortable2/admin.py#L571

If you want me to implement this as a sponsored feature, please contact me on my private email address.

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

2 participants