Skip to main content

Like ericflo's django pagination, but this one does the sorting! used with ericflo's pagination, displaying tabular paginated and sortable data is very easy

Project description

How to use django-sorting
----------------------------

``django-sorting`` allows for easy sorting, and tables headers (<th>) generation
without modifying your views.

There are really 5 steps to setting it up with your projects.

1. List this application in the ``INSTALLED_APPS`` portion of your settings
file. Your settings file might look something like::

INSTALLED_APPS = (
# ...
'sorting',
)

2. Install the sorting middleware. Your settings file might look something
like::

MIDDLEWARE_CLASSES = (
# ...
'sorting.middleware.SortingMiddleware',
)

3. If it's not already added in your setup, add the request context processor.
Note that context processors are set by default implicitly, so to set them
explicitly, you need to copy and paste this code into your under
the value TEMPLATE_CONTEXT_PROCESSORS::

("django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request")

4. Add this line at the top of your template to load the sorting tags:

{% load sorting_tags %}


5. 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 %}


6. Now, you want to display different headers with links to sort
your objects_list:

<tr>
{% th first_name Name %}
{% th creation_date Creation %}
...
</tr>

The first argument is a field of the objects list, and the second
one(optional) is a title that would be displayed. The previous
snippet will be rendered like this:

<tr>
<th><a href="?sort=first_name" title="Name">Name</a></th>
<th><a href="?sort=creation_date" title="Name">Creation</a></th>
...
</tr>


That's it!

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-sorting-0.1.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file django-sorting-0.1.tar.gz.

File metadata

File hashes

Hashes for django-sorting-0.1.tar.gz
Algorithm Hash digest
SHA256 2ea0ffa577f520c622a93b529bd61fb1bb64a4b6a8d639c21ef97ce2a43cd373
MD5 6af1c5629362ee734e850e582efef740
BLAKE2b-256 4559ad07cf0fc622f9ade0765ead9d2ce1314b8800dcf0ca78336f3106c133ba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page