Skip to content

Lh4cKg/wagtail-admin-sortable

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

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