Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -37,7 +44,7 @@ class Category(AdminSortable, ClusterableModel):
verbose_name_plural = "Categories"
```

##### or
##### or

```python
from django.db import models
Expand All @@ -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.
MIT licensed.
4 changes: 2 additions & 2 deletions wagtail_adminsortable/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down