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.

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 workaround right now is to set list_per_page to a bigger value and not reordering filtered changelists.

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.12.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

django_admin_ordering-0.12.0-py2.py3-none-any.whl (19.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: django-admin-ordering-0.12.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for django-admin-ordering-0.12.0.tar.gz
Algorithm Hash digest
SHA256 af97b7c3449584fe6e5be7ab58e2d6d26b8449f3a62885b2c416d93c0f425970
MD5 877a38f78c8662c4efcc8dd81e03bcd4
BLAKE2b-256 8ee895fbf2e62d19d69c1d112ad3f825460a89dc348d4c27dccc96e83cfd398c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_admin_ordering-0.12.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for django_admin_ordering-0.12.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 47e6551159d566225cdf30e1672cea3908a391c710dbc3f319cebe1c772063c7
MD5 942638083698a4055b0b30570d12fd45
BLAKE2b-256 54f4f2761e194964f7a402c8287e173073faf2d8a1f13947612cdb0ac9e967b7

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