The "Django Admin Search" is a advanced search modal for django admin
Project description
Django Admin Search
this project implement a search modal in django admin to filter your queryset.
Obs: this project works only in django admin
Images:
Button in admin list:
Modal opened:
Install:
pip install django-admin-search
Usage:
-
Add to your INSTALLED_APPS, in settings.py:
INSTALLED_APPS = [ ... 'django_admin_search', ... ]
-
Create a search form for model:
from .models import Area from django.forms import ModelForm, Form from django.forms import DateField, CharField, ChoiceField, TextInput class YourFormSearch(Form): name = CharField(required=False) date = DateField(required=False, widget=TextInput( attrs={ 'filter_method': '__gte', } ))
-
In your admin:
from django_admin_search.admin import AdvacedSearchAdmin from .models import YourModel from .form import YourForm, YourFormSearch @register(YourModel) class YourAdmin(AdvacedSearchAdmin): form = YourForm search_form = YourFormSearch
Advanced:
-
to multiple filters in same field:
class YourFormSearch(Form): ... name = CharField(required=False) begin = DateField(required=False, widget=TextInput( attrs={ 'filter_field': 'date', 'filter_method': '__gte', } )) end = DateField(required=False, widget=TextInput( attrs={ 'filter_field': 'date', 'filter_method': '__lte', } ))
-
add placeholder and mask
class YourFormSearch(Form): ... date = DateField(required=False, widget=TextInput( attrs={ 'data-mask': "00/00/0000", 'placeholder': 'MM/DD/YYYY' } ))
-
Custom filter query for a field
from django_admin_search.admin import AdvacedSearchAdmin from .models import YourModel from .form import YourForm, YourFormSearch @register(YourModel) class YourAdmin(AdvacedSearchAdmin): def search_FieldNameHere(request, field_value, param_values): """ intercept query filter for description field """ query = Q() # your Q logic here return query
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-admin-search-0.2.2.tar.gz
(125.8 kB
view hashes)
Close
Hashes for django-admin-search-0.2.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c915bda8dea78a3011919aa4625f92ddb0a96063796c9a683ad7cd758206537 |
|
MD5 | 5547667cb5c7f34d1af4dc4e3edb7695 |
|
BLAKE2b-256 | 85547ed7fc7a8f8d452ab9c49ee2a8160048c2915a551f324ef2120ec3ea5b5f |