2👍
Rather than reinventing the wheel, the solution i propose is to enjoy a reusable app that does it right.
django-tables2
simplifies the task of turning sets of data into HTML tables. It has
native support for pagination and sorting. It does for HTML tables
what django.forms does for HTML forms. e.g.Its features include:
- Any iterable can be a data-source, but special support for Django querysets is included.
- The builtin UI does not rely on JavaScript.
- Support for automatic table generation based on a Django model.
- Supports custom column functionality via subclassing.
- Pagination.
- Column based table sorting.
- Template tag to enable trivial rendering to HTML.
- Generic view mixin for use in Django 1.3.
👤jpic
2👍
Personally I would use something like jQuery tablesorter to solve this. This will save you a roundtrip to the server for each sort.
- [Django]-Django Import/Export to multiple Models (foreignkey)
- [Django]-Django-rest-framework authentication: require key parameter in URL?
- [Django]-Admin site automatically get current user
- [Django]-I can't insert a footnote into the copied text
1👍
Another option is the use of django-filter. Just check out the example app:
- [Django]-Difference between using name of model and model for ForeignKey
- [Django]-How to get the list of columns in a Django Queryset?
- [Django]-Django : saving form to database
Source:stackexchange.com