Easily reorder the order of items within the django admin backend.
Project description
Welcome to django-reorder-items-widget
Links
Description
Reorder your items by simply dragging them to their new position. This works fine within admin changelists and inline formsets.
The main component is the ReorderItemsWidget which provides the drag and drop interface on top of an index field and updates the indexes of listed items on form submission.
Still there are some neccessary setups to make a full functional admin integration of the reorder items feature: we need a model field for the widget, an appropriate admin configuration and we probably do not want to update indexes manually when adding or removing items bypassing the widget. Therefore we use some signal handlers for the model field.
This app provides everything you need to make this setup as easy as possible.
Installation
Install via pip:
pip install django-reorder-items-widget
Add reorder_items_widget to your INSTALLED_APPS:
INSTALLED_APPS = [
'reorder_items_widget',
...
]
Getting started
Setup for a reorderable changelist
Add a ReorderItemsField field to your model:
from django.db import models
from reorder_items_widget import ReorderItemsField
class Item(models.Model):
...
index = models.ReorderItemsField()
class Meta:
ordering = ('index',)
Setup your model admin using the ReorderItemsModelAdmin:
from django.contrib import admin
from reorder_items_widget import ReorderItemsModelAdmin
class ItemModelAdmin(ReorderItemsModelAdmin):
...
You don't have to do anything with the index field in your model admin. It's already setup by the base class.
Now you can reorder your items within the changelist only by drag and drop. And completely forget about the index field which won't show up in the whole admin backend at all.
Setup for a reorderable inline
Again setup your models with a ReorderItemsField:
from django.db import models
from reorder_items_widget import ReorderItemsField
class Container(models.Model):
...
class Item(models.Model):
...
index = models.ReorderItemsField(grouped_by=['container'])
container = models.ForeignKey(Container, on_delete=models.CASCADE)
class Meta:
ordering = ('container', 'index')
Mind the grouped_by argument for the ReorderItemsField. This argument tells
the field, that the ordering should be container specific. For each container
object the indexes of the related items will start anew with zero.
Now setup the model admins using the ReorderItemsInline:
from django.contrib import admin
from reorder_items_widget import ReorderItemsInline
class ItemInline(ReorderItemsInline):
...
class ContainerModelAdmin(admin.ModelAdmin):
inlines = (ItemInline,)
Again there is no need to handle the index field.
Now visit the changeform of your container object and enjoy reordering its items.
Caveats
The widget will always number your items sequentially. So reordering a filtered list of items might have unexpected results. Paging however should not be a problem since the index of the first listed item will be used as a base.
Contribute
Feedback, feature requests, bug reports or pull requests are most welcome. Just use the common github infrastructure.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_reorder_items_widget-1.2.0.tar.gz.
File metadata
- Download URL: django_reorder_items_widget-1.2.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a49ef1a8935d166595e4b147b10d12502f1b39e8990c2d1b66636a99098463a2
|
|
| MD5 |
419c378a9e6ebf8195865b68829f5e67
|
|
| BLAKE2b-256 |
6be0c1a4041f1ff4eedae5fd68edcd6068eee3f1be604067916fe03c3d65e235
|
Provenance
The following attestation bundles were made for django_reorder_items_widget-1.2.0.tar.gz:
Publisher:
publish.yml on thomst/django-reorder-items-widget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_reorder_items_widget-1.2.0.tar.gz -
Subject digest:
a49ef1a8935d166595e4b147b10d12502f1b39e8990c2d1b66636a99098463a2 - Sigstore transparency entry: 1712019843
- Sigstore integration time:
-
Permalink:
thomst/django-reorder-items-widget@f7e93db89066751b239d6a904b6e991af1fc3f51 -
Branch / Tag:
refs/tags/1.2.0 - Owner: https://github.com/thomst
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f7e93db89066751b239d6a904b6e991af1fc3f51 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_reorder_items_widget-1.2.0-py3-none-any.whl.
File metadata
- Download URL: django_reorder_items_widget-1.2.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f88242e328a54dc3843ea083c1847836f70afb8e64a23a2ef02bf43357b82860
|
|
| MD5 |
f630fc06ec74c3fb0bc6a22de513be6e
|
|
| BLAKE2b-256 |
63004024582bb1410c073b2391ee748d3bb89042a4e326a831ac8f8cfa7a5cb2
|
Provenance
The following attestation bundles were made for django_reorder_items_widget-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on thomst/django-reorder-items-widget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_reorder_items_widget-1.2.0-py3-none-any.whl -
Subject digest:
f88242e328a54dc3843ea083c1847836f70afb8e64a23a2ef02bf43357b82860 - Sigstore transparency entry: 1712019853
- Sigstore integration time:
-
Permalink:
thomst/django-reorder-items-widget@f7e93db89066751b239d6a904b6e991af1fc3f51 -
Branch / Tag:
refs/tags/1.2.0 - Owner: https://github.com/thomst
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f7e93db89066751b239d6a904b6e991af1fc3f51 -
Trigger Event:
push
-
Statement type: