I was wondering if there is a way to use the power of Django Admin's filtering/ordering/paginating/search capabilities in a regular view.
What I mean is that I have a model, some fields on it. I'd like to have a "search" form, where fields would be defined much like using admin.ModelAdmin. User would be able to search (using provided fields), filter by values, paginate through pages of result table etc. All that without minimal amount of work on my part, eg. just configuration which fields should be used in the form. Something like this:
class SchoolAdmin(ModelAdmin):
list_display = ('id', 'name', )
list_display_links = ('name', )
search_fields = ('name', )
list_filter = ('type', )
Is there something like this available? Or do I have to code it myself?
Edit:
Features I require from such a plugin/application are:
Alasdair's django-tables2 only matches 1st and 2nd conditions.
The django functionality you mention isn't really reusable in custom views as of Django 1.3. There was recently some discussion on the django-developers group about splitting out admin functionality to make it reusable.
I have come across two projects that might be useful to you, django-tables2 and django-filter. They both offer slightly different things, I think you're looking for a mixture of the two.
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
Django-filter is a reusable Django application for allowing users to filter queryset dynamically. It requires Python 2.4 or higher. For usage and installation instructions consult the docs directory.
Django-filter can be used for generating interfaces similar to the Django admin's
list_filter
interface. It has an API very similar to Django'sModelForms
.
To extend on Alasdair's answer, I added a simple module that adds simple filtering to django-tables2. See https://github.com/benjiec/django-tables2-simplefilter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With