The steps for enabling drag-and-drop sorting functionality is identical to Grappelli’s (even with the vanilla Django admin), so the Grappelli documentation for this feature is the best reference. This is equally true of sortables in Django Suit—do not follow Django Suit’s instructions for sortables, as they will not work. The other features of Grappelli have not been ported to work with vanilla Django, but in principle they should all still work with nested inlines using django-nested-admin if Grappelli is installed. If you run into any difficulty with this, please create an issue on this project’s Github.
If you want to have a sortable inline and also want to hide the field you’re sorting, you can use
SortableHiddenMixin. Note that this mixin sets
position by default (though this can be overridden by setting
sortable_field_name on your inline class) and must be inherited prior to
import nested_admin from django.contrib import admin from .models import TableOfContents, TocArticle, TocSection class TocArticleInline(nested_admin.SortableHiddenMixin, nested_admin.NestedStackedInline): model = TocArticle class TocSectionInline(nested_admin.SortableHiddenMixin, nested_admin.NestedStackedInline): model = TocSection inlines = [TocArticleInline] @admin.register(TableOfContents) class TableOfContentsAdmin(nested_admin.NestedModelAdmin): inlines = [TocSectionInline]
Adding or removing an inline fires the
formset:undeleted events. Less likely to be used, but still available, are the following events:
- Fired whenever the state of a formset changes
- Fired after an inline has been initialized, either on load or after being added
- Fired whenever a drag-and-drop operation or removal necessitates changing the
namechanges, but in cases where they do, use this event to refresh or reinitialize the bindings.