A Django model field for controlling sort order.
Project description
Sort Order Field provides a Django model field for controlling sort order. The field provides an admin widget which makes it easy to arrange related models in an inline form.
This is a very naive sort field, with no awareness of the model’s ordering property and very specific admin support. However, it provides a simple and accessible user interface which could be useful for certain situations.
Installation
Add “sort_order_field” to your INSTALLED_APPS setting:
INSTALLED_APPS = [ ... 'sort_order_field', ]
Basic usage
Add a SortOrderField to one of your models:
from django.db import models from sort_order_field import SortOrderField class Poll(models.Model): question = models.CharField(max_length=100) class PollOption(models.Model): class Meta: ordering = ('sort_order',) poll = models.ForeignKey('Poll', on_delete=models.CASCADE) sort_order = SortOrderField(_("Sort")) label = models.CharField(max_length=100)
Add the sortable model to an inline model admin for your parent model:
from django.contrib import admin from . import models class PollOptionInline(admin.TabularInline): model = models.PollOption fields = ('sort_order', 'label',) @admin.register(models.Poll) class PollAdmin(admin.ModelAdmin): fields = ('question',) inlines = (PollOptionInline,)
The sort order field will be rendered as a text field with JavaScript enhancements. When the user enters a new sort order, the inline forms will be reorganized according to that change. The sort order fields will also be bound by their initial values, in order to avoid conflicts if the same objects appear in different inlines.
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
Hashes for django-sort-order-field-1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3a1bebd4dc059e9046599359ef8a9ae113ead3f7a4c3bbad2256933de2a1004 |
|
MD5 | 597cd32835ad0a4c58b4eafb25a94221 |
|
BLAKE2b-256 | 4caa83b2f21c40a05d1de9b4a44127c63d7e73fe3ae1b80dd6ef3f3fe3eb2fc3 |
Hashes for django_sort_order_field-1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd334d393e6e82386b0ad18a70621cfe2950ea99afe664df24fd4703ac051d51 |
|
MD5 | a6b68e9ebb5f11671d95d742b06564cf |
|
BLAKE2b-256 | b61310d69abbb4ed4146a32fcc6576b1b56453f08d7d550e99a59e1a80497b30 |