# Django Orderable
Add manual sort order to Django objects via an abstract base class and admin classes. Project includes:
* Abstract base Model
* Admin class
* Inline admin class
* Admin templates
## Demo
![django-orderable demo](https://cloud.githubusercontent.com/assets/30606/6326221/667992e0-bb47-11e4-923e-29334573ff5c.gif)
## Installation
Grab from the PyPI:
pip install django-orderable
Add to your INSTALLED_APPS:
...
'orderable',
...
Subclass the Orderable class:
from orderable.models import Orderable
class Book(Orderable):
...
Subclass the appropriate Orderable admin classes:
from orderable.admin import OrderableAdmin, OrderableTabularInline
class SomeInlineClass(OrderableTabularInline):
...
class SomeAdminClass(OrderableAdmin):
list_display = ('__unicode__', 'sort_order_display')
...
jQuery and jQuery UI are used in the Admin for the draggable UI. You may override the versions with your own (rather than using Google's CDN):
class SomeAdminClass(OrderableAdmin):
class Media:
extend = False
js = (
'path/to/jquery.js',
'path/to/jquery.ui.js',
)
## Notes
### `class Meta`
If your subclass of `Orderable` defines [`class Meta`](https://docs.djangoproject.com/en/2.0/ref/models/options/) then make sure it subclasses `Orderable.Meta` one so the model is sorted by `sort_order`. ie:
class MyOrderable(Orderable):
class Meta(Orderable.Meta):
...
### Custom Managers
Similarly, if your model has a custom manager, subclass `orderable.managers.OrderableManager` instead of `django.db.models.Manager`.
### Transactions
Saving orderable models invokes a fair number of database queries, and in order
to avoid race conditions should be run in a transaction.
### Adding Orderable to Existing Models
You will need to populate the required `sort_order` field. Typically this is
done by adding the field in one migration with a default of `0`, then creating
a data migration to set the value to that of its primary key:
for obj in orm['appname.Model'].objects.all():
obj.sort_order = obj.pk
obj.save()
### Multiple Models using Orderable
When multiple models inherit from Orderable the `next()` and `previous()`
methods will look for the next/previous model with a sort order. However you'll
likely want to have the various sort orders determined by a foreign key or some
other predicate. The easiest way (currently) is to override the method in
question.
Raw data
{
"_id": null,
"home_page": "https://github.com/incuna/django-orderable",
"name": "django-orderable",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Incuna Ltd",
"author_email": "admin@incuna.com",
"download_url": "https://files.pythonhosted.org/packages/08/96/6b12528fc96938a27504c4b1d4907be0aa1fbefbd7034c7436f765f0350c/django-orderable-6.1.2.tar.gz",
"platform": null,
"description": "# Django Orderable\n\n\nAdd manual sort order to Django objects via an abstract base class and admin classes. Project includes:\n\n* Abstract base Model\n* Admin class\n* Inline admin class\n* Admin templates\n\n\n## Demo\n\n\n![django-orderable demo](https://cloud.githubusercontent.com/assets/30606/6326221/667992e0-bb47-11e4-923e-29334573ff5c.gif)\n\n## Installation\n\n\nGrab from the PyPI:\n\n pip install django-orderable\n\n\nAdd to your INSTALLED_APPS:\n\n ...\n 'orderable',\n ...\n\nSubclass the Orderable class:\n\n from orderable.models import Orderable\n\n\n class Book(Orderable):\n ...\n\nSubclass the appropriate Orderable admin classes:\n\n from orderable.admin import OrderableAdmin, OrderableTabularInline\n\n\n class SomeInlineClass(OrderableTabularInline):\n ...\n\n class SomeAdminClass(OrderableAdmin):\n list_display = ('__unicode__', 'sort_order_display')\n ...\n\n\njQuery and jQuery UI are used in the Admin for the draggable UI. You may override the versions with your own (rather than using Google's CDN):\n\n class SomeAdminClass(OrderableAdmin):\n class Media:\n extend = False\n js = (\n 'path/to/jquery.js',\n 'path/to/jquery.ui.js',\n )\n\n\n## Notes\n\n### `class Meta`\n\nIf your subclass of `Orderable` defines [`class Meta`](https://docs.djangoproject.com/en/2.0/ref/models/options/) then make sure it subclasses `Orderable.Meta` one so the model is sorted by `sort_order`. ie:\n\n class MyOrderable(Orderable):\n class Meta(Orderable.Meta):\n ...\n\n### Custom Managers\n\nSimilarly, if your model has a custom manager, subclass `orderable.managers.OrderableManager` instead of `django.db.models.Manager`.\n\n### Transactions\n\nSaving orderable models invokes a fair number of database queries, and in order\nto avoid race conditions should be run in a transaction.\n\n### Adding Orderable to Existing Models\n\nYou will need to populate the required `sort_order` field. Typically this is\ndone by adding the field in one migration with a default of `0`, then creating\na data migration to set the value to that of its primary key:\n\n\n for obj in orm['appname.Model'].objects.all():\n obj.sort_order = obj.pk\n obj.save()\n\n\n### Multiple Models using Orderable\n\nWhen multiple models inherit from Orderable the `next()` and `previous()`\nmethods will look for the next/previous model with a sort order. However you'll\nlikely want to have the various sort orders determined by a foreign key or some\nother predicate. The easiest way (currently) is to override the method in\nquestion.\n\n\n\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Add manual sort order to Django objects via an abstract base class and admin classes.",
"version": "6.1.2",
"project_urls": {
"Homepage": "https://github.com/incuna/django-orderable"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "80d8f0f4919e0bffd1a6eeb5a1202ea94538b61b6715189cfaa33c30b3e281b6",
"md5": "ddc092e9126b4db4a85af3852124d42d",
"sha256": "0de9b8d554ef05ad7f964a66b5d424b2610ca796bf4e2b939f9993a432256772"
},
"downloads": -1,
"filename": "django_orderable-6.1.2-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "ddc092e9126b4db4a85af3852124d42d",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 16619,
"upload_time": "2023-06-29T19:28:27",
"upload_time_iso_8601": "2023-06-29T19:28:27.635360Z",
"url": "https://files.pythonhosted.org/packages/80/d8/f0f4919e0bffd1a6eeb5a1202ea94538b61b6715189cfaa33c30b3e281b6/django_orderable-6.1.2-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "08966b12528fc96938a27504c4b1d4907be0aa1fbefbd7034c7436f765f0350c",
"md5": "adc401b8be52061b9cf7022d8e1ad1db",
"sha256": "3dacd778d65cddbe4afa221d5c8b141cdccbdcb1ca6e90549e0e11df5f6f5dd3"
},
"downloads": -1,
"filename": "django-orderable-6.1.2.tar.gz",
"has_sig": false,
"md5_digest": "adc401b8be52061b9cf7022d8e1ad1db",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12152,
"upload_time": "2023-06-29T19:28:29",
"upload_time_iso_8601": "2023-06-29T19:28:29.879964Z",
"url": "https://files.pythonhosted.org/packages/08/96/6b12528fc96938a27504c4b1d4907be0aa1fbefbd7034c7436f765f0350c/django-orderable-6.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-29 19:28:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "incuna",
"github_project": "django-orderable",
"travis_ci": true,
"coveralls": true,
"github_actions": false,
"requirements": [],
"lcname": "django-orderable"
}