Skip to content

Generic drag-and-drop ordering for objects in the Wagtail admin interface

Notifications You must be signed in to change notification settings

Lh4cKg/wagtail-admin-sortable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wagtail-admin-sortable

Generic drag-and-drop ordering for objects in the Wagtail admin interface

Quick Start

Install wagtail_adminsortable

$ pip install wagtail_adminsortable

Add wagtail_adminsortable to INSTALLED_APPS in settings.py for your Django project:

INSTALLED_APPS = [
  ...
  'wagtail_adminsortable',
]
Integrate your models
from django.db import models
from modelcluster.models import ClusterableModel
from wagtail_adminsortable.models import AdminSortable


class Category(AdminSortable, ClusterableModel):
    title = models.CharField('Title', max_length=255, null=True, blank=True)

    class Meta(AdminSortable.Meta):
        verbose_name = "Category"
        verbose_name_plural = "Categories"
or
from django.db import models
from modelcluster.models import ClusterableModel


class Category(ClusterableModel):
    title = models.CharField('Title', max_length=255, null=True, blank=True)
    my_order = models.IntegerField(default=0, blank=False, null=False)

    class Meta:
        ordering = ['my_order']
        verbose_name = "Category"
        verbose_name_plural = "Categories"
and define ORDERING_FIELD in settings.py
ORDERING_FIELD = 'my_order'
Integrate into a list view
In wagtail_hooks.py, add a mixin class to augment the functionality for sorting (be sure to put the mixin class before ModelAdmin):
from wagtail.contrib.modeladmin.options import ModelAdmin
from wagtail_adminsortable.admin import SortableAdminMixin


class CategoryAdmin(SortableAdminMixin, ModelAdmin):
    pass
License

Copyright © 2019 Lasha Gogua.

MIT licensed.

About

Generic drag-and-drop ordering for objects in the Wagtail admin interface

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published