Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Sorting templates API using sorting-bootstrap templatetags and Bootstrap classes.

Project Description


Django-sorting-bootstrap is a pluggable mini-API to easy add sorting for querysets, links and table headers in Django templates. There is also a new tag that creates headers for sorting tables using Bootstrap’s layout.


To install django-sorting-bootstrap simply run:

pip install django-sorting-bootstrap


Include sorting_bootstrap in your INSTALLED_APPS

Put {% load sorting_tags %} at top of your templates.

Your templates have four tags available:

auto_sort sort_link sort_th sort_headers

Basic usage:

{% auto_sort queryset %}
{% sort_link "link text" "field_name" %}
{% sort_th "link text" "field_name" %}
{% sort_headers simpleschangelist %}


It sorts the queryset in place and replaces the queryset by the sorted queryset.

This needs to be called prior to a slice has been taken from a queryset. (Ordering can not be done after the slice has been taken.) In particular this will not work with generuc view object_list.

Basic usage:

{% auto_sort queryset %}


It works the same way as sort_link, but the difference is the output template that renders a table header tag <th> using Bootstrap classes and Glyphicons.

Basic usage:

{% sort_th "link text" "field_name" %}


This function is somewhat more complicated to use, but it builds the whole table headers for sorting. In order to use it you have to pass in your view a SimplesChangeList (from sorting_bootstrap.views). Let’s have an exemple using a view extending Generic ListView.

Basic usage:

from django.views.generic import ListView
class MyView(ListView)
  def get_context_data(self, **kwargs):
            # Calls the base implementation first to get a context
        context = super(self.__class__, self).get_context_data(**kwargs)

        from sorting_bootstrap.views import SimpleChangeList
        # Gets the fields that are going to be in the headers
        list_display = [ for i in self.model._meta.fields]
        # Doesnt show ID field
        list_display = list_display[1:]
        cl = SimpleChangeList(self.request, self.model, list_display)
        # Pass a change list to the views
        context['cl'] = cl

You also need to call the function in your template:

{% sort_headers cl %}


This app is based on Agiliq’s django-sorting 0.1. It has two improvements over it: the new tags and the Twitter Bootstrap compliance idea.

Release History

This version
History Node


History Node


History Node


History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(9.5 kB) Copy SHA256 Hash SHA256
Source None May 27, 2016

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Google Google Cloud Servers Fastly Fastly CDN StatusPage StatusPage Statuspage DigiCert DigiCert EV Certificate