Package: django-search-views
django-search-viewsThis package provides a Django class-based view used for showing a list
of objects with a search form. Full documentation at
(http://inmagik.github.io/django-search-views/).Features:allows searching multiple fieldssupports paginationset filtering operators for each fieldset fixed filtersuse lists of values for filtersInstallationFrom pypi:pip install django-search-viewsFrom source:python setup.py installUsageImportant: until v.1.0 API might be subject to changes. Please take
a look at thechangelogand don’t hesitate to mail us
or open an issue if you have troubles migration from an older version.
Sorry about this!.SearchListViewtbwExampleThe following code sets up model, form and view for displaying an
“Actors List”.models.py:class Actor(models.Model):
    name = models.CharField(max_length=32)
    surname = models.CharField(max_length=32)
    age = models.IntegerField()forms.pyfrom .models import Actor
from django import forms
class ActorSearchForm(forms.Form):
    search_text =  forms.CharField(
                    required = False,
                    label='Search name or surname!',
                    widget=forms.TextInput(attrs={'placeholder': 'search here!'})
                  )

    search_age_exact = forms.IntegerField(
                    required = False,
                    label='Search age (exact match)!'
                  )

    search_age_min = forms.IntegerField(
                    required = False,
                    label='Min age'
                  )


    search_age_max = forms.IntegerField(
                    required = False,
                    label='Max age'
                  )views.pyfrom .model import Actor
from .forms import ActorSearchForm
from search_views.search import SearchListView
from search_views.filters import BaseFilter

class ActorsFilter(BaseFilter):
    search_fields = {
        'search_text' : ['name', 'surname'],
        'search_age_exact' : { 'operator' : '__exact', 'fields' : ['age'] },
        'search_age_min' : { 'operator' : '__gte', 'fields' : ['age'] },
        'search_age_max' : { 'operator' : '__lte', 'fields' : ['age'] },

    }

class ActorsSearchList(SearchListView):
    model = Actor
    paginate_by = 30
    template_name = "actors/actors_list.html"
    form_class = ActorSearchForm
    filter_class = ActorsFilterview template “actors/actors_list.html”:{% extends "base.html" %}


{% block content%}

<div class="container">

    <h2>Actors list</h2>

    <form class="form-inline" action="" method="GET">
        {{ form }}
        <button class="btn" type="submit">Search</button>
        </fieldset>
    </form>

    <table class="table table-bordered table-condensed">
        <tr>
            <th>Name</th>
            <th>Surname</th>
            <th>Age</th>
        </tr>
        {% for object in object_list %}
        <tr>
            <td>{{object.name}}</td>
            <td>{{object.surname}}</td>
            <td>{{object.age}}</td>
        </tr>
        {% endfor %}
    </table>

    {% if is_paginated %}
        {% include "paginator.html" %}
    {% endif %}

</div>

{% endblock %}Changelog0.2.0filters are now configured in their own class derived fromsearchlist_views.filters.BaseFilter.0.3.0Renamed main package fromsearchlist_viewstosearch_views.0.3.1Python 3 compatibilityLicense and developmentThis project is MIT licensed and maintained byInmagik, suggestions and pull requests are
welcome via theGithub project
page