Custom filters for Django Admin
Project description
Custom filters for Django Admin
##Information 1. Custom choice filter
1.1. Filter by multiple choices (Less and Equal, More and Equal, Equal) in each metrics / dimensions lookups
1.2. Add multiple metrics / dimensions for combined queries
1.3. You can add any name for your metrics / dimension to label
2. Custom dropdown filter
2.1. Filter uses default view of django list_filter in condition when values less than slice count (default slice count is 3)
2.2. When values in filter more than slice count view changed to select element.
##Install
You can install this by using pip
:
pip install django-admin-custom-filters
##Usage
1. Custom choice filter
1.1. Create child class by using parent class CustomInputChoiceFilter.
from django_admin_custom_filters.filters import CustomInputChoiceFilter
class ChildFilter(CustomInputChoiceFilter):
1.2. Edit variables - title, parameters_title, parameters_name.
from django_admin_custom_filters.filters import CustomInputChoiceFilter
class ChildFilter(CustomInputChoiceFilter):
title = "Test Filter"
parameters_name = ['variable_1', 'variable_2']
parameters_title = ['Variable First', 'Variable Second']
1.3. Create child class by using parent class CustomModelAdmin.
from django_admin_custom_filters.admin import CustomModelAdmin
class TestAdmin(CustomModelAdmin):
1.4. Add to list_filter your filter.
from django_admin_custom_filters.admin import CustomModelAdmin
from .filters import ChildFilter
from .models import Test
class TestAdmin(CustomModelAdmin):
list_filter = (
ChildFilter,
)
class Meta:
model = Test
2. Custom dropdown filter
2.1. You can create child class for change slice count.
from django_admin_custom_filters.filters import DropdownFilter
class CustomDropdownFilter(DropdownFilter):
slice_count = 2
2.2. Add to list_filter your filter.
from django.contrib import admin
from .filters import CustomDropdownFilter
from .models import Test
class TestAdmin(admin.ModelAdmin):
list_filter = (
('variable_1', CustomDropdownFilter),
)
class Meta:
model = Test
3. Img from examples folder code
3.1. Custom choice filter and Custom dropdown filter
3.2. Custom dropdown filter by slice more than values in filter.
![Image2](img/image 2.png?raw=true)
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
Built Distribution
Hashes for django_admin_custom_filters-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3103e2b866d1cac97073f2780d6739c05fd174128e2a077bd05d1d8c8e908709 |
|
MD5 | 2a8af24fd4edf1016fccc87f4b259d9a |
|
BLAKE2b-256 | 88e32129d2d2632350e0b48334a1fe4b55f791cf484bfc043894675cbf6f4df9 |
Hashes for django_admin_custom_filters-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 895759e8231b24c4a3865dc3f7cf95da617363f0272da25968db290eae7bb899 |
|
MD5 | 26c178b9db732f48f60771546d37931c |
|
BLAKE2b-256 | bf79135319fc87f59bc9df20dc44af5fcd655510df6cdd60efe35804359667b0 |