django-inline-orderable

An easy way of making inlines orderable using drag-and-drop.


License
BSD-3-Clause
Install
pip install django-inline-orderable==0.1.1

Documentation

django-inline-orderable

An easy way of making inlines orderable using drag-and-drop.

Installation

Install inline_orderable:

pip install django-inline-orderable

Add inline_orderable to INSTALLED_APPS in settings.py.

Usage

Step 1

Declare your model as a subclass of Orderable

from inline_orderable.models import Orderable

class MyModel(Orderable):
    ...

    class Meta(Orderable.Meta):
        pass

This will add an extra column called order.

The Meta class declaration is NOT necessary, add it only if you need to set your own meta attributes.

Step 2

Declare your admin inline class as a subclass of OrderableStackedInline or OrderableTabularInline

from inline_orderable.admin import OrderableStackedInline, OrderableTabularInline

class MyModelInline(OrderableStackedInline):
    ...

class MyModel2Inline(OrderableTabularInline):
    ...

Step 3

Include jQuery and jQuery.ui

class MyParentModelAdmin(admin.ModelAdmin):
    inlines = (MyModelInline, )

    class Media:
        js = (
            'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js',
            'http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js',
        )

Step 4 (optional)

django-inline-orderable uses staticfiles available from Django 1.3.

If you're using Django 1.2 just copy the media files to your MEDIA_ROOT.

Thanks