Easily reorder the order of items within the django admin backend.
Project description
Welcome to django-reorder-items-widget
Description
Reorder your items by simply dragging them to their new position. This works fine within django admin's changelists or inline model forms.
All you need to do is to use an editable index field with the famous
ReorderItemsWidget of this app.
Installation
Install via pip:
pip install django-reorder-items-widget
Setup
Add reorder_items_widget to your INSTALLED_APPS:
INSTALLED_APPS = [
'reorder_items_widget',
...
]
Add a index field to your model:
class Item(models.Model):
index = models.PositiveSmallIntegerField()
...
class Meta:
ordering = ('index',)
Using the ReorderItemsWidget with your index field only makes sense in result lists or inline modeladmin forms. A simple way to put the widget in place is a custom model form:
class ReorderItemForm(forms.ModelForm):
class Meta:
widgets={'index': ReorderItemsWidget()}
Now you can use this form with your changelist by overwriting the
get_changelist_form method of your model admin:
class BaseItemAdmin(admin.ModelAdmin):
list_editable = ("index",)
list_display = ("index", ...)
def get_changelist_form(self, request, **kwargs):
kwargs.setdefault('form', ReorderItemForm)
return super().get_changelist_form(request, **kwargs)
NOTE: Mind that your index field must be editable.
To use the widget with your inline modeladmin simple at your form to the
TabularInline class:
class ItemInline(admin.TabularInline):
form = ReorderItemForm
fields = ("index", ...)
...
That's it.
Caveats
The widget will always number your items sequentially. Reordering items in a filtered list might be have unexpected results. Paging however should not be a problem since indexes are updated using the lowest one as base.
General considerations on switching index values
There is a general problem with switching values on a unique index field: In mysql like databases you will run into a constraint violation - even if you update all items in a single update transaction.
To work around this you can either obmit the unique constraint. Or implement a complex saving logic like saving changed indexes as negative values first and update them to their positiv counterpart afterwards.
Contribute
Feedback, feature requests, bug reports or pull requests are most welcome. Just use the common github infrastructure.
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
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.0.0.tar.gz.
File metadata
- Download URL: django_reorder_items_widget-1.0.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9446f947c73fe5efdbb33229b0013cf6a1652706b3e1e4d2fa5024886efa5bb8
|
|
| MD5 |
7098c7857bf24ac6c7c7faceb50f8dbf
|
|
| BLAKE2b-256 |
da8e30b4fe31442e5e06f7da0f3b54a672fdeed9629f4710f557f59c4417c81e
|
Provenance
The following attestation bundles were made for django_reorder_items_widget-1.0.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.0.0.tar.gz -
Subject digest:
9446f947c73fe5efdbb33229b0013cf6a1652706b3e1e4d2fa5024886efa5bb8 - Sigstore transparency entry: 1307597282
- Sigstore integration time:
-
Permalink:
thomst/django-reorder-items-widget@019be9040ffa01d35b8591bd3c0c6699e1a3a745 -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/thomst
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@019be9040ffa01d35b8591bd3c0c6699e1a3a745 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_reorder_items_widget-1.0.0-py3-none-any.whl.
File metadata
- Download URL: django_reorder_items_widget-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.9 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 |
4e34dfd1eb72b1b1cdc11380b65d72e73a8655d195848134efbfb9e1416568ac
|
|
| MD5 |
6e9398aac73eaf656ceceea709683a96
|
|
| BLAKE2b-256 |
2452938a1109e784e64132dbf909b7db53a07c82c15e355c20ef54496d4dbe89
|
Provenance
The following attestation bundles were made for django_reorder_items_widget-1.0.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.0.0-py3-none-any.whl -
Subject digest:
4e34dfd1eb72b1b1cdc11380b65d72e73a8655d195848134efbfb9e1416568ac - Sigstore transparency entry: 1307597350
- Sigstore integration time:
-
Permalink:
thomst/django-reorder-items-widget@019be9040ffa01d35b8591bd3c0c6699e1a3a745 -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/thomst
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@019be9040ffa01d35b8591bd3c0c6699e1a3a745 -
Trigger Event:
push
-
Statement type: