Skip to main content

Orderable change lists and inlines done right^Wsimple

Project description

CI Status

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


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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_admin_ordering-0.18.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file django_admin_ordering-0.18.0.tar.gz.

File metadata

  • Download URL: django_admin_ordering-0.18.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for django_admin_ordering-0.18.0.tar.gz
Algorithm Hash digest
SHA256 2439a977b9e822b3b070a885a81757ca6286a9593124f9bffb1b28df0b3395c6
MD5 2b851353e3ba05b80274d035f3078faf
BLAKE2b-256 9ca01727593161af5ca55878b7e2907485526825e9fe65c9751aa9d24243dc6a

See more details on using hashes here.

File details

Details for the file django_admin_ordering-0.18.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin_ordering-0.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e49e893583dc5c3b9632df5ab851b0bb4cd5f612f17c51529e80a07809ff27a1
MD5 f33650fb4cb1ffcb071f2c10aaf49c3b
BLAKE2b-256 11ecf88beb554d89e107301d42c5b406019a73d889344ffb3ae30e8496b511a5

See more details on using hashes here.

Supported by

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