Advanced search syntax for Django Admin
Project description
Django Admin Advanced Search
Advanced search syntax for Django Admin that enables powerful filtering capabilities directly from the search bar.
Features
- Enhanced search capabilities in Django Admin with advanced syntax
- Support for field-specific searches with various operators
- Case-sensitive and case-insensitive matching options
- Quoted values support for exact phrase matching
- Multiple conditions combination with AND logic
- Seamless integration with existing Django Admin interfaces
- Performance-conscious implementation with database-level filtering
- Automatic field type detection (string, number, date, datetime)
- Type-specific parsing rules for appropriate operators
- Support for comparison operators on number and date fields
Requirements
- Python >= 3.12
- Django >= 5.1
Note: This package has been tested specifically on Django 5.1, 5.2 with Python 3.12, 3.13, 3.14. While it may work on other versions, compatibility is not guaranteed for versions outside this range.
Installation
pip install django-admin-advanced-search
Usage
- Add
django_admin_advanced_searchto yourINSTALLED_APPS:
INSTALLED_APPS = [
...
'django_admin_advanced_search',
...
]
- Use the advanced search in your admin classes:
from django.contrib import admin
from django_admin_advanced_search.mixins import AdvancedSearchMixin
class MyModelAdmin(AdvancedSearchMixin, admin.ModelAdmin):
search_fields = ['name', 'description', 'author__name'] # Fields that can be searched
# Your other admin configuration
admin.site.register(MyModel, MyModelAdmin)
Search Syntax
| Syntax | Description | Example | SQL Equivalent |
|---|---|---|---|
field:value |
Case-insensitive contains | name:john |
name ILIKE '%john%' |
field:=value |
Case-insensitive exact | name:=john |
name ILIKE 'john' |
field:==value |
Case-sensitive exact | name:==John |
name = 'John' |
field:!value |
Case-sensitive contains | name:!john |
name LIKE '%john%' |
field:*suffix |
Case-insensitive endswith | name:*son |
name ILIKE '%son' |
field:!*suffix |
Case-sensitive endswith | name:!*son |
name LIKE '%son' |
field:prefix* |
Case-insensitive startswith | name:john* |
name ILIKE 'john%' |
field:!prefix* |
Case-sensitive startswith | name:!john* |
name LIKE 'john%' |
field:>value |
Greater than (numbers/dates) | price:>100 |
price > 100 |
field:>=value |
Greater than or equal (numbers/dates) | date:>=2023-01-01 |
date >= '2023-01-01' |
field:<value |
Less than (numbers/dates) | price:<1000 |
price < 1000 |
field:<=value |
Less than or equal (numbers/dates) | date:<=2023-12-31 |
date <= '2023-12-31' |
field:"quoted value" |
Values with spaces (dates/times) | created_at:<"2023-12-31 23:59:59" |
created_at < '2023-12-31 23:59:59' |
"quoted values" |
Exact phrase matching | name:"John Doe" |
name ILIKE 'John Doe' |
Examples
title:django*- Items with titles starting with "django" (case-insensitive)author__name:*smith- Items by authors whose names end with "smith" (case-insensitive)title:==Learning Python- Items with the exact title "Learning Python" (case-sensitive)title:"Python Programming"- Items with titles containing the exact phrase "Python Programming"title:python author__name:john- Items with titles containing "python" AND authors whose names contain "john"price:>29.99- Items with price greater than 29.99publication_date:>=2023-01-01- Items published on or after January 1, 2023created_at:<"2023-12-31 23:59:59"- Items created before December 31, 2023 11:59:59 PM (note the quotes around the datetime value with spaces)
Documentation
Database Collation and Performance Notes
- This package generates database-level filters, ensuring optimal performance
- For case-insensitive operations, the package uses the database's native case-insensitive comparison operators when available
- Make sure your database columns have appropriate collation settings for optimal performance
- Complex searches with multiple fields may generate complex SQL queries; consider adding database indexes on frequently searched fields
- When using related field lookups (e.g.,
author__name:john), ensure foreign key relationships are properly indexed - For number and date fields, the package automatically detects field types and applies appropriate comparison operators
- DateTime values containing spaces must be quoted to be parsed correctly (e.g.,
created_at:<"2023-12-31 23:59:59")
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project Link: https://github.com/shifenhutu/django-admin-advanced-search
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_admin_advanced_search-0.1.3.tar.gz.
File metadata
- Download URL: django_admin_advanced_search-0.1.3.tar.gz
- Upload date:
- Size: 42.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
febeb1bc6fc6154156c8c32437bf897c99f6db9dc87a52c6ccfaa76fd7693a47
|
|
| MD5 |
554a378004be63f58a87520f1ef607c2
|
|
| BLAKE2b-256 |
42dce52e6f8920db6e7bc1b33553bb925a3a74ca3091be3c17b6b94e3ba9c0f9
|
Provenance
The following attestation bundles were made for django_admin_advanced_search-0.1.3.tar.gz:
Publisher:
publish.yml on shifenhutu/django-admin-advanced-search
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_admin_advanced_search-0.1.3.tar.gz -
Subject digest:
febeb1bc6fc6154156c8c32437bf897c99f6db9dc87a52c6ccfaa76fd7693a47 - Sigstore transparency entry: 730947186
- Sigstore integration time:
-
Permalink:
shifenhutu/django-admin-advanced-search@a3f8f5e0da4b1608e1cac615ec42be8285edab0b -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/shifenhutu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a3f8f5e0da4b1608e1cac615ec42be8285edab0b -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_admin_advanced_search-0.1.3-py3-none-any.whl.
File metadata
- Download URL: django_admin_advanced_search-0.1.3-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30bc1dbcb425a600a628f3a8cf334222376fa7ffc2c50d80b2622aa7d24fcca9
|
|
| MD5 |
953c5660eef48454327201bf78d4f7c3
|
|
| BLAKE2b-256 |
49e2588fa6e946e316f6ceb0fd4311216ad1ebdcc61d207d9fb1af35888dd5a4
|
Provenance
The following attestation bundles were made for django_admin_advanced_search-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on shifenhutu/django-admin-advanced-search
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_admin_advanced_search-0.1.3-py3-none-any.whl -
Subject digest:
30bc1dbcb425a600a628f3a8cf334222376fa7ffc2c50d80b2622aa7d24fcca9 - Sigstore transparency entry: 730947192
- Sigstore integration time:
-
Permalink:
shifenhutu/django-admin-advanced-search@a3f8f5e0da4b1608e1cac615ec42be8285edab0b -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/shifenhutu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a3f8f5e0da4b1608e1cac615ec42be8285edab0b -
Trigger Event:
release
-
Statement type: