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.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"
    ordering_field = "ordering"  # The default.

    # 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", "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

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


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

Uploaded Source

Built Distribution

django_admin_ordering-0.18.2-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for django_admin_ordering-0.18.2.tar.gz
Algorithm Hash digest
SHA256 7e897462738f26e3890a54b56024539b179c4578486cf7309e17f44981c01a7f
MD5 da89b7fb14bcea7b5616047d73388e8a
BLAKE2b-256 1e6e24c2ed96f6de26e1ade1620d1386cad35f56b3d63979aa44542f2c824e54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_admin_ordering-0.18.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7cfb2e303db0adbe55f08774c46ac812f572039d18a670aee7e8185e65e5df79
MD5 a6d38f68a2fb2f3fdfdbc8fb6d1b5e7c
BLAKE2b-256 8e30e846a28f3dd9d317d777bd3bfcd0808bd93471284824f39d1bd0de2b55fd

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