Orderable change lists and inlines done right^Wsimple
Project description
Please refer to the CI build linked above for the currently supported combinations of Python and Django.
Installation
pip install django-admin-ordering, and add admin_ordering to INSTALLED_APPS.
Usage
First, you need a model ordered by an integer field. If you are happy with a model where 1. the ordering field is called ordering and 2. the ordering field is automatically initialized so that new objects are ordered last you can also inherit the abstract admin_ordering.models.OrderableModel model. If you define your own class Meta you should inherit OrderableModel.Meta so that the ordering attribute is set to the correct value:
from admin_ordering.models import OrderableModel
class MyModel(OrderableModel):
# ...
class Meta(OrderableModel):
# ...
Orderable change lists
from admin_ordering.admin import OrderableAdmin
@admin.register(MyModel)
class MyModelAdmin(OrderableAdmin, admin.ModelAdmin):
# The field used for ordering. Prepend a minus for reverse
# ordering: "-order"
ordering_field = "order"
# You may optionally hide the ordering field in the changelist:
# ordering_field_hide_input = False
# The ordering field must be included both in list_display and
# list_editable:
list_display = ["name", "order"]
list_editable = ["order"]
Orderable inlines
from admin_ordering.admin import OrderableAdmin
class MyModelTabularInline(OrderableAdmin, admin.TabularInline):
model = MyModel
# Same as above; "-order" is also allowed here:
ordering_field = "order"
# ordering_field_hide_input = False
OrderableAdmin comes with a default of extra = 0 (no extra empty inlines shown by default). It is strongly recommended to leave the changed default as-is, because otherwise you’ll end up with invalid inlines just because you wanted to change the ordering.
Limitations
Starting with Django 1.9 newly created inlines are automatically assigned a good ordering value. Earlier versions do not support the required formset:added signal.
OrderableAdmin can be used both for inlines and parents, but this also means that you cannot register a model directly with OrderableAdmin.
Using django-admin-ordering with filtered or paginated lists may produce unexpected results. The recommendation right now is to set list_per_page to a bigger value and not reordering filtered changelists.
Note that django-admin-ordering assigns ordering values in increments of 10, emphasizing that the ordering value should not have any significance apart from giving relative ordering to elements.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_admin_ordering-0.15.0.tar.gz
.
File metadata
- Download URL: django_admin_ordering-0.15.0.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75b2db5d5f798f2f40ebdc0446179fb369e93eac46e731cd5e84506c2c13a9ce |
|
MD5 | 0e8aa85bd992d24fea12f07ad0778e50 |
|
BLAKE2b-256 | ffcd5de39c59412b9f852331a84b467fb381c71a967fb6ae0f8da2625cd296c3 |
File details
Details for the file django_admin_ordering-0.15.0-py3-none-any.whl
.
File metadata
- Download URL: django_admin_ordering-0.15.0-py3-none-any.whl
- Upload date:
- Size: 20.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 477f1551bed353fb4019d2bc28b7b353f4b98f059aa73fb3727d9798d92cb392 |
|
MD5 | 88c4cd2709eb7087e7103f248ab6e42b |
|
BLAKE2b-256 | ddb132480d7322f1e2798d73f6fb80b4b9184ab322fc02e59fd4767962981072 |