Django admin filters for CharFields with select and autocomplete functionality
Project description
Django CharField Filters
A reusable Django app that provides advanced admin filters for CharField fields, including both dropdown select and autocomplete functionality.
Features
- Easy-to-use filters for CharField fields in Django admin
- Three filter types:
- Select: Dropdown with all unique values
- Autocomplete: Type-to-search functionality
- Autocomplete Select: Hybrid filter combining dropdown and search
- User-friendly interface with clear button for quick filter removal
- Dynamic filtering as you type
- Automatic title generation from field names
- Cached lookups for better performance
- Compatible with Django 4.2.0+
Installation
pip install django-charfield-filters
Add 'charfield_filters' to your INSTALLED_APPS:
INSTALLED_APPS = [
...
'charfield_filters',
...
]
Usage
Basic Usage
from django.contrib import admin
from charfield_filters.admin import CharFieldFilterAdmin
@admin.register(YourModel)
class YourModelAdmin(CharFieldFilterAdmin):
list_display = ['name', 'category'] # Fields to display
charfield_filter_fields = ['name', 'category'] # Fields to filter
charfield_filter_type = 'autocomplete_select' # 'select', 'autocomplete', or 'autocomplete_select'
Using the Mixin
If you need to combine with other admin classes:
from django.contrib import admin
from charfield_filters.admin import CharFieldFilterMixin
@admin.register(YourModel)
class YourModelAdmin(CharFieldFilterMixin, admin.ModelAdmin):
list_display = ['name', 'category']
charfield_filter_fields = ['name', 'category']
charfield_filter_type = 'autocomplete_select'
Filter Types
-
Select Filter (
charfield_filter_type = 'select'):- Creates a dropdown with all unique values
- Best for fields with a limited number of unique values
- Provides exact matching
-
Autocomplete Filter (
charfield_filter_type = 'autocomplete'):- Creates a search input field
- Best for fields with many unique values
- Provides case-insensitive partial matching
-
Autocomplete Select Filter (
charfield_filter_type = 'autocomplete_select'):- Combines dropdown and search functionality
- Shows all options in a searchable dropdown
- Includes clear button (×) for easy filter removal
- Best for fields with moderate number of values
- Supports both browsing and searching
Configuration
Admin Class Options
charfield_filter_fields: List of CharField field names to create filters forcharfield_filter_type: Type of filter to use ('select', 'autocomplete', or 'autocomplete_select')
Example
from django.db import models
from django.contrib import admin
from charfield_filters.admin import CharFieldFilterAdmin
class Book(models.Model):
title = models.CharField(max_length=200)
author = models.CharField(max_length=100)
genre = models.CharField(max_length=50)
@admin.register(Book)
class BookAdmin(CharFieldFilterAdmin):
list_display = ['title', 'author', 'genre']
charfield_filter_fields = ['author', 'genre'] # Add filters for author and genre
charfield_filter_type = 'autocomplete_select' # Use hybrid filter for both fields
Requirements
- Python 3.8+
- Django 4.2.0+
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you have any questions or need help with the package, please open an issue on GitHub.
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_charfield_filters-0.1.3.tar.gz.
File metadata
- Download URL: django_charfield_filters-0.1.3.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd6bdbf3b65fb03d5ca5dfd9b3e5a2b32a64fd9183257b64106b68535bf0efd5
|
|
| MD5 |
c752f6ba04a30c44db7121d63b7e19c7
|
|
| BLAKE2b-256 |
0b7b04d4a75186ab43b3d4ca931e8343805f38d93c2ca5fe723cda4dacaa5f4f
|
File details
Details for the file django_charfield_filters-0.1.3-py3-none-any.whl.
File metadata
- Download URL: django_charfield_filters-0.1.3-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b854c78b9dfd58e88e03200411a2088443821951816a1528ee3096a68ad34bda
|
|
| MD5 |
939ab1406853661a09d78f36cda9f123
|
|
| BLAKE2b-256 |
a9cd60925bf20da0377cf443458794de2d32408623d29831dedea509a13fd69c
|