Skip to main content

Orderable change lists and inlines done right^Wsimple

Project description

https://travis-ci.org/matthiask/django-admin-ordering.svg?branch=master

Please refer to the Travis 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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-admin-ordering-0.13.0.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

django_admin_ordering-0.13.0-py2.py3-none-any.whl (19.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-admin-ordering-0.13.0.tar.gz.

File metadata

  • Download URL: django-admin-ordering-0.13.0.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

File hashes

Hashes for django-admin-ordering-0.13.0.tar.gz
Algorithm Hash digest
SHA256 0151455bbbd9cf917bc9c3c1fb0847df0c13c3e38e7eda603082f1fdf5e9ad6c
MD5 2cb2e67e90b8f35416c0a25e720d89e2
BLAKE2b-256 05465df67f92074be83304149cb08a6558143d75810b1d602de3070071a297ea

See more details on using hashes here.

File details

Details for the file django_admin_ordering-0.13.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_admin_ordering-0.13.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

File hashes

Hashes for django_admin_ordering-0.13.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8ffd8bc54b04b0d0168a7098162949552883600577313cab394efccf1a517dc1
MD5 3b177d884d1c906a8eab787b9773725f
BLAKE2b-256 0346ac6738a2e5b2f6509de1ed7a246ad88aef23e539f247f6e637ee32a9915a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page