jrief/django-admin-sortable2

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

cknoll opened this issue · 1 comments

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,)