django-search-views
This 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 fields
supports pagination
set filtering operators for each field
set fixed filters
use lists of values for filters
Installation
From pypi:
pip install django-search-views
From source:
python setup.py install
Usage
Important: until v.1.0 API might be subject to changes. Please take a look at the changelog and don’t hesitate to mail us or open an issue if you have troubles migration from an older version. Sorry about this!.
SearchListView
tbw
Example
The 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.py
from .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.py
from .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 = ActorsFilter
view 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 %}
Changelog
0.2.0
filters are now configured in their own class derived from searchlist_views.filters.BaseFilter.
0.3.0
Renamed main package from searchlist_views to search_views.
0.3.1
Python 3 compatibility
License and development
This project is MIT licensed and maintained by Inmagik, suggestions and pull requests are welcome via the Github project page
Metadata
Release files for django-search-views 0.3.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-search-views-0.3.7.tar.gz | 6.9 kB | Without provenance | Details |
Release files / django-search-views-0.3.7.tar.gz
| Download URL | django-search-views-0.3.7.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba54cf9ad003edece2d2f785d7519daef4a95fedb42bd357baee9e85856881e7
|
|
BLAKE2b-256 checksum How to use checksums |
30ea38a2fc57322183915563429606e922b547455f3dc2469c593ccc13e28b76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-search-views 0.3.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.