The "Django Admin Search" is a advanced search modal for django admin
Project description
Django Admin Search
===================
# Install:
pip install django-admin-search
# Usage:
1. Add to your INSTALLED_APPS, in settings.py:
INSTALLED_APPS = [
...
'django_admin_search',
...
]
2. 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',
}
))
3. In your admin:
from django_admin_search.admin import BaseAdvacedSearchAdmin
from .models import YourModel
from .form import YourForm, YourFormSearch
@register(YourModel)
class ModelAdmin(BaseAdvacedSearchAdmin):
form = YourForm
search_form = YourFormSearch
# Advanced:
1. 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',
}
))
2. add placeholder and mask
class YourFormSearch(Form):
...
date = DateField(required=False, widget=TextInput(
attrs={
'data-mask': "00/00/0000",
'placeholder': 'MM/DD/YYYY'
}
))
===================
# Install:
pip install django-admin-search
# Usage:
1. Add to your INSTALLED_APPS, in settings.py:
INSTALLED_APPS = [
...
'django_admin_search',
...
]
2. 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',
}
))
3. In your admin:
from django_admin_search.admin import BaseAdvacedSearchAdmin
from .models import YourModel
from .form import YourForm, YourFormSearch
@register(YourModel)
class ModelAdmin(BaseAdvacedSearchAdmin):
form = YourForm
search_form = YourFormSearch
# Advanced:
1. 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',
}
))
2. add placeholder and mask
class YourFormSearch(Form):
...
date = DateField(required=False, widget=TextInput(
attrs={
'data-mask': "00/00/0000",
'placeholder': 'MM/DD/YYYY'
}
))
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.1.1.tar.gz
(124.2 kB
view hashes)
Close
Hashes for django-admin-search-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68a78f3a9c236020d69d7c20b756b8d15800530018d40ab22a79cbefcdc2f0ec |
|
MD5 | 07ebdb7d5a17260c27bd8b1437c88fe7 |
|
BLAKE2b-256 | 588eca202e3ce65ea4782f627d9650c025bb6bfcee6dcc777f5ddfd0b0693864 |