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.Meta):
# ...
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: "-ordering"
# Doesn't have to be provided as long as you're using the default.
# ordering_field = "ordering"
# You may optionally hide the ordering field in the changelist:
# ordering_field_hide_input = False
# The ordering field can optionally be automatically renumbered when
# the page loads. This may be useful if you have existing data which
# isn't ordered yet.
# ordering_field_renumber_on_load = False
# The ordering field must be included both in list_display and
# list_editable:
list_display = ["name", "ordering"]
list_editable = ["ordering"]
Orderable inlines
from admin_ordering.admin import OrderableAdmin
class MyModelTabularInline(OrderableAdmin, admin.TabularInline):
model = MyModel
# Same as above; "-ordering" is also allowed here:
# ordering_field = "ordering"
# ordering_field_hide_input = False
# ordering_field_renumber_on_load = 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
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.19.1.tar.gz
.
File metadata
- Download URL: django_admin_ordering-0.19.1.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60f7d36ee69bf227bc9544b9b66ca226a6418bc2686be3e8375f3461710878e1 |
|
MD5 | 0c9a51f0caa8b85547520bd6af990fb1 |
|
BLAKE2b-256 | 574cfa6e95035f6255f6e6a2748ed6a8d097cae58ba129ed8886604407b879d5 |
File details
Details for the file django_admin_ordering-0.19.1-py3-none-any.whl
.
File metadata
- Download URL: django_admin_ordering-0.19.1-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfc0857677176599d1a811a1e4fa2d889c2650ad59de7b8f8679e0e2f41d0a85 |
|
MD5 | 5e1916a2f56139caf2e944c5962e2af6 |
|
BLAKE2b-256 | db9ca12f73e52b7bfff526910df5d8f1fff06b98c35f39e9784a86109dcb406e |