diff --git a/README.md b/README.md index 6ce5117..2a77f4f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/iambrandontaylor/django-admin-sortable.svg?branch=master)](https://travis-ci.org/iambrandontaylor/django-admin-sortable) -Current version: 1.7.3 +Current version: 1.7.4 This project makes it easy to add drag-and-drop ordering to any model in Django admin. Inlines for a sortable model may also be made sortable, @@ -16,6 +16,8 @@ django-admin-sortable 1.5.2 introduced backward-incompatible changes for Django django-admin-sortable 1.6.6 introduced a backward-incompatible change for the `sorting_filters` attribute. Please convert your attributes to the new tuple-based format. +django-admin-sortable 1.7.1 and higher are compatible with Python 3. + ## Installation 1. `$ pip install django-admin-sortable` @@ -33,6 +35,7 @@ Download django-admin-sortable from [source](https://github.com/iambrandontaylor 1. Add `adminsortable` to your `INSTALLED_APPS`. 2. Ensure `django.core.context_processors.static` is in your `TEMPLATE_CONTEXT_PROCESSORS`. + ### Static Media Preferred: Use the [staticfiles app](https://docs.djangoproject.com/en/1.6/ref/contrib/staticfiles/) @@ -41,6 +44,7 @@ Alternate: Copy the `adminsortable` folder from the `static` folder to the location you serve static files from. + ### Testing Have a look at the included sample_project to see working examples. The login credentials for admin are: admin/admin @@ -70,15 +74,14 @@ have an inner Meta class that inherits from `Sortable.Meta` def __unicode__(self): return self.title +A common use case is to have child objects that are sortable relative to a parent. If your parent object is also sortable, here's how you would set up your models and admin options: -It is also possible to order objects relative to another object that is a ForeignKey. A small caveat here is that `Category` must also either inherit from `Sortable` or include an `order` property which is a `PositiveSmallInteger` field. This is due to the way Django admin instantiates classes. - + # models.py from adminsortable.fields import SortableForeignKey - #models.py class Category(Sortable): class Meta(Sortable.Meta): - pass + verbose_name_plural = 'Categories' title = models.CharField(max_length=50) ... @@ -93,8 +96,53 @@ It is also possible to order objects relative to another object that is a Foreig def __unicode__(self): return self.title + # admin + from adminsortable.admin import SortableAdmin + + from your_app.models import Category, Project + + admin.site.register(Category, SortableAdmin) + admin.site.register(Project, SortableAdmin) + + +Sometimes you might have a parent model that is not sortable, but has inline child models that are. In that case define your models and admin options as such: + + from adminsortable.fields import SortableForeignKey + + # models.py + class Category(models.Model): + class Meta: + verbose_name_plural = 'Categories' + + title = models.CharField(max_length=50) + ... + + class Project(Sortable): + class Meta(Sortable.Meta): + pass + + category = SortableForeignKey(Category) + title = models.CharField(max_length=50) + + def __unicode__(self): + return self.title + + # admin + from adminsortable.admin import NonSortableParentAdmin, SortableStackedInline + + from your_app.models import Category, Project + + class ProjectInline(SortableStackedInline): + model = Project + extra = 1 + + class CategoryAdmin(NonSortableParentAdmin): + inlines = [ProjectInline] + + admin.site.register(Category, CategoryAdmin) + +The `NonSortableParentAdmin` class is necessary to wire up the additional URL patterns and JavaScript that Django Admin Sortable needs to make your inline models sortable. -Sortable has one field: `order` and adds a default ordering value set to `order`. #### Model Instance Methods Each instance of a sortable model has two convenience methods to get the next or previous instance: @@ -176,6 +224,18 @@ There are also generic equivalents that you can inherit from: """Your generic inline options go here""" +If your parent model is *not* sortable, but has child inlines that are, your parent model needs to inherit from `NonSortableParentAdmin`: + + from adminsortable.admin import (NonSortableParentAdmin, + SortableTabularInline) + + class ChildTabularInline(SortableTabularInline): + model = YourModel + + class ParentAdmin(NonSortableParentAdmin): + inlines = [ChildTabularInline] + + #### Overriding `queryset()` django-admin-sortable supports custom queryset overrides on admin models and inline models in Django admin! @@ -324,10 +384,6 @@ with: -### Known Issue(s) -Because of the way inline models are added to their parent model in the change form, it is not currently possible to have sortable inline models whose parent does not inhert from `Sortable`. - - ### Rationale Other projects have added drag-and-drop ordering to the ChangeList view, however this introduces a couple of problems... @@ -345,9 +401,8 @@ ordering on top of that just seemed a little much in my opinion. django-admin-sortable is currently used in production. -### What's new in 1.7.3? -- Travis CI integration -- get_next/previous instance methods +### What's new in 1.7.4? +- Non-sortable parent models can now have sortable child models without having to override templates thanks to the new `NonSortableParentAdmin` class. ### Future diff --git a/adminsortable/__init__.py b/adminsortable/__init__.py index e042c34..c8897a7 100644 --- a/adminsortable/__init__.py +++ b/adminsortable/__init__.py @@ -1,4 +1,4 @@ -VERSION = (1, 7, 3) # following PEP 386 +VERSION = (1, 7, 4) # following PEP 386 DEV_N = None