Skip to main content

Django admin filters for CharFields with select and autocomplete functionality

Project description

Django CharField Filters

PyPI PyPI - Python Version Django Version

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

  1. 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
  2. Autocomplete Filter (charfield_filter_type = 'autocomplete'):

    • Creates a search input field
    • Best for fields with many unique values
    • Provides case-insensitive partial matching
  3. 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 for
  • charfield_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

django_charfield_filters-0.1.3.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_charfield_filters-0.1.3-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

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

Hashes for django_charfield_filters-0.1.3.tar.gz
Algorithm Hash digest
SHA256 dd6bdbf3b65fb03d5ca5dfd9b3e5a2b32a64fd9183257b64106b68535bf0efd5
MD5 c752f6ba04a30c44db7121d63b7e19c7
BLAKE2b-256 0b7b04d4a75186ab43b3d4ca931e8343805f38d93c2ca5fe723cda4dacaa5f4f

See more details on using hashes here.

File details

Details for the file django_charfield_filters-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_charfield_filters-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b854c78b9dfd58e88e03200411a2088443821951816a1528ee3096a68ad34bda
MD5 939ab1406853661a09d78f36cda9f123
BLAKE2b-256 a9cd60925bf20da0377cf443458794de2d32408623d29831dedea509a13fd69c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page