Easy sorting of tables with Django
Project description
webstack-django-sorting allows for easy sorting of data tables and 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.
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 install it in your project
The 5 steps to use webstack-django-sorting in your Django project:
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
NoneRelease 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 webstack-django-sorting-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d9ac44cff8dc0e6fa68fb95ce1ae5ed644b4531bbe4227e95eb851998b9292d |
|
MD5 | d02a87e0eaf8ce7de9f2d8ef552979c5 |
|
BLAKE2b-256 | b4bbcb69a6a85f1cfd286f38433fb928a13a6e69ba0941fabd250ff0f39e641c |
Hashes for webstack_django_sorting-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a29e44c05e5ec126faa9eaf08029fee98593bf52d0eadb0f0774698b323f181 |
|
MD5 | f11a812386216a0e79723cccdfda0c7f |
|
BLAKE2b-256 | a5344e307a9dd84c07698bfe10e00fcf4c24595d8c5b03975eea8c54c0e804ad |