OrderedModel intends to help you create models which can be
moved up\down (or left\right) with respect to each other.
How to use
There are a few simple steps to follow to make your models orderable:
git clone git://github.com/kirelagin/django-orderedmodel.git.
- Copy (or, even better, symlink)
orderedmodeldirectory to your Django project.
- (Optional) Add
- Derive your Model from
- Derive your ModelAdmin from
reorderfield to yout ModelAdmin's
Now you can use
order_by('order') in your query to get instances of your model
in desired order (actually it is not neccessary to call
unless you have changed default ordering in your model's Meta).
Suppose you have a django app called testapp.
You need an orderable model
from django.db import models from orderedmodel import OrderedModel class TestModel(OrderedModel): name = models.CharField(max_length=30)
from django.contrib import admin from orderedmodel import OrderedModelAdmin from testapp.models import TestModel class TestModelAdmin(OrderedModelAdmin): list_display = ['name', 'reorder'] admin.site.register(TestModel, TestModelAdmin)
Yep! Now if you create several instances of your model and look into admin site you'll see something like this:
- Added support to Django 1.4.x (by Francesco Facconi - Immediatic)