parent
bee71e6d40
commit
2543f02ce7
17
README.md
17
README.md
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
[](https://travis-ci.org/iambrandontaylor/django-admin-sortable)
|
||||
|
||||
Current version: 2.0.0
|
||||
Current version: 2.0.1
|
||||
|
||||
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,
|
||||
|
|
@ -61,16 +61,15 @@ Inlines may be drag-and-dropped into any order directly from the change form.
|
|||
### Models
|
||||
To add sortability to a model, you need to inherit `SortableMixin` and at minimum, define:
|
||||
|
||||
- The field which should be used for ordering, which must be one of the integer fields defined in Django's ORM:
|
||||
- The field which should be used for `Meta.ordering`, which must resolve to one of the integer fields defined in Django's ORM:
|
||||
- `PositiveIntegerField`
|
||||
- `IntegerField`
|
||||
- `PositiveSmallIntegerField`
|
||||
- `SmallIntegerField`
|
||||
- `BigIntegerField`
|
||||
- An `order_field_name` string that is synonymous to the field used for ordering (defaults to 'order' for backwards compatibility). *This field is not required if your ordering field is named "order".*
|
||||
- The `ordering` option on your model's `Meta` class, which should be the same as the `order_field_name`
|
||||
|
||||
For a smoother admin experience, I recommend setting the field to `editable=False` and adding indexing to the field you use for ordering.
|
||||
- `Meta.ordering` **must only contain one value**, otherwise, your objects will not be sorted correctly.
|
||||
- It is recommended that you set `editable=False` and `db_index=True` on the field defined in `Meta.ordering` for a seamless Django admin experience and faster lookups on the objects.
|
||||
|
||||
Sample Model:
|
||||
|
||||
|
|
@ -87,14 +86,10 @@ Sample Model:
|
|||
|
||||
# define the field the model should be ordered by
|
||||
the_order = models.PositiveIntegerField(default=0, editable=False, db_index=True)
|
||||
order_field_name = 'the_order'
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
||||
#### Important Note About Ordering...
|
||||
If you do not set the `Meta` `ordering` option to the same value as `order_field_name`, your objects will not be sorted/ordered correctly.
|
||||
|
||||
|
||||
#### Common Use Case
|
||||
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:
|
||||
|
|
@ -462,8 +457,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 2.0.0?
|
||||
- Sortable class has become SortableMixin which is now unobtrusive, allowing you to create sortable abstract classes.
|
||||
### What's new in 2.0.1?
|
||||
- Sortables now determine the field to use for sorting via the `Meta.ordering` definition rather than a separate string on the model.
|
||||
|
||||
|
||||
### Future
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ class SortableForeignKey(ForeignKey):
|
|||
"""
|
||||
Field simply acts as a flag to determine the class to sort by.
|
||||
This field replaces previous functionality where `sortable_by` was
|
||||
definied as a model property that specified another model class.
|
||||
defined as a model property that specified another model class.
|
||||
"""
|
||||
|
||||
def south_field_triple(self):
|
||||
|
|
|
|||
Loading…
Reference in New Issue