Easy sorting of tables with Django
Project description
webstack-django-sorting
What?
webstack-django-sorting
is a Django app which allows for easy sorting of
data tables. You don't need to change anything to your views to use it. It
provides sorting links for table headers. It is the perfect companion of
django-pagination.
A demonstration of the features is provided in testproj
directory.
Features
- Django ORM or Python sorting
- Switches between ascending, descending, and no sorting
- Provides links to sort on different criterions
- Visual feedback on applied ordering
- Supports Python 2.7, 3.5+
- Supports translation of link titles
Upgrade from v0.5.0
To upgrade to webstack-django-sorting
v1.0.0+, you must remove the old middleware
webstack_django_sorting.middleware.SortingMiddleware
from MIDDLEWARE_CLASSES
list.
How to use it in your project
-
pip install webstack_django_sorting
-
Add the application to the
INSTALLED_APPS
list:INSTALLED_APPS = [ # ... 'webstack_django_sorting', ]
-
Check the request context processor is loaded in
TEMPLATES
options:TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ # ... 'django.template.context_processors.request', # ... ], }, }, ]
-
Add this line at the top of your template to load the sorting tags:
{% load sorting_tags %}
-
Decide on a variable that you would like to sort, and use the autosort tag on that variable before iterating over it:
{% autosort object_list %}
-
Now, you want to display different headers with links to sort your objects_list:
<tr> <th>{% anchor first_name _("Name") %}</th> <th>{% anchor creation_date _("Creation") %}</th> </tr>
The first argument is a field or an attribute of the objects list, and the second one (optional) is a title that would be displayed. The previous snippet will be rendered like this in French:
<tr> <th><a href="/path/to/your/view/?sort=first_name" title="Nom">Nom</a></th> <th><a href="/path/to/your/view/?sort=creation_date" title="Création">Création</a></th> </tr>
If your application doesn't support internationalization, you can use a simple
{% anchor first_name Name %}
.
That's it!
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
File details
Details for the file webstack-django-sorting-1.0.2.tar.gz
.
File metadata
- Download URL: webstack-django-sorting-1.0.2.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a69b7b46cee50ca079cccf4df68687040369f347b5d57db5843a9fb9fa8b0f21 |
|
MD5 | 808b54cd9183e78cfdcb016c2f37bc63 |
|
BLAKE2b-256 | e52b7a157994184ce7d3dcdf8cdbc1654a85e67915444c0e0bdd3f5aff7e5d3e |
File details
Details for the file webstack_django_sorting-1.0.2-py2.py3-none-any.whl
.
File metadata
- Download URL: webstack_django_sorting-1.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10cca962fe40c7a2b599112f679938accaeaf9c30a19ae4a5cb86f4a29fb7e7b |
|
MD5 | 05af0ce8a734a48c4dc23b7a452fbd0e |
|
BLAKE2b-256 | 0a7162db221bcd29e16c7bbaaac543f3057a19a35f48b2a3dee7044581c82d4f |