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
773 stars 180 forks source link

Incorrect code example in documentation (Sec. "Many-to-Many Relations") #357

Closed cknoll closed 1 year ago

cknoll commented 1 year ago

I think the code example in section Setup the Tabular Inlines ... contains mistakes.

Current code:

from django.contrib import admin
from adminsortable2.admin import SortableInlineAdminMixin
from models import Panel

class ButtonTabularInline(SortableInlineAdminMixin, admin.TabularInline):
      # We don't use the Button model but rather the juction model specified on Panel.
      model = Panel.buttons.through

@admin.register(Panel)
class PanelAdmin(admin.ModelAdmin)
      inlines = (ButtonTabularInline,)

Improved version

from django.contrib import admin
from adminsortable2.admin import SortableInlineAdminMixin, SortableAdminBase  # ←changed
from models import Panel

class ButtonTabularInline(SortableInlineAdminMixin, admin.TabularInline):
      # We don't use the Button model but rather the juction model specified on Panel.
      model = Panel.buttons.through

@admin.register(Panel)
class PanelAdmin(SortableAdminBase, admin.ModelAdmin): # ←changed
      inlines = (ButtonTabularInline,)
sahilasopa commented 3 months ago

Reopen, the issue is still the same