diff --git a/README.md b/README.md index 452b3b3..450c516 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,33 @@ # wagtail-admin-sortable + Generic drag-and-drop ordering for objects in the Wagtail admin interface ### Quick Start -Install **wagtail_adminsortable** +Install **wagtail_adminsortable** via PyPi ```bash $ pip install wagtail_adminsortable +``` -``` +or via Github for latest version -Add ``wagtail_adminsortable`` to ``INSTALLED_APPS`` in ``settings.py`` for your Django project: +```bash +$ pip install git+https://github.com/Lh4cKg/wagtail-admin-sortable + +``` + +Add `wagtail_adminsortable` and `wagtail.contrib.modeladmin,` to `INSTALLED_APPS` in `settings.py` for your Django project: ```python INSTALLED_APPS = [ ... + 'wagtail.contrib.modeladmin', 'wagtail_adminsortable', ] ``` - ##### Integrate your models ```python @@ -37,7 +44,7 @@ class Category(AdminSortable, ClusterableModel): verbose_name_plural = "Categories" ``` -##### or +##### or ```python from django.db import models @@ -62,20 +69,21 @@ 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): +###### In wagtail_hooks.py (in your app directory), add a mixin class to augment the functionality for sorting (be sure to put the mixin class before ModelAdmin): ```python -from wagtail.contrib.modeladmin.options import ModelAdmin +from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register from wagtail_adminsortable.admin import SortableAdminMixin class CategoryAdmin(SortableAdminMixin, ModelAdmin): - pass -``` + model = YourModel +modeladmin_register(CategoryAdmin) +``` ##### License Copyright © 2019 Lasha Gogua. -MIT licensed. \ No newline at end of file +MIT licensed. diff --git a/wagtail_adminsortable/mixins.py b/wagtail_adminsortable/mixins.py index 7feeb1d..7eda9e3 100644 --- a/wagtail_adminsortable/mixins.py +++ b/wagtail_adminsortable/mixins.py @@ -11,14 +11,14 @@ class AjaxableResponseMixin(object): """ def form_invalid(self, form): response = super(AjaxableResponseMixin, self).form_invalid(form) - if self.request.is_ajax(): + if self.request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest': return JsonResponse(form.errors, status=400) else: return response def form_valid(self, form): super(AjaxableResponseMixin, self).form_valid(form) - if self.request.is_ajax(): + if self.request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest': objects = json.loads(self.request.POST.get('objects', '[]')) data = { 'message': 'success'