Advanced query builder UI for Django admin changelists.
Project description
Django Easy Query Builder
django-easy-query-builder is a Django admin extension that adds a safe, UI-driven advanced query builder to changelist pages.
It lets admins build nested filters visually, serialize them into URL parameters, validate them server-side, and execute them as Django ORM queries.
Why This Project
Django admin search is great for simple use cases, but it gets limiting when users need:
- multiple nested
AND/OR/NOTgroups - related-model filtering across deep relations
- reproducible filter URLs
- reusable saved query views
This package provides that out of the box with a mixin.
Features
- Drop-in
ModelAdminmixin (AdvancedSearchAdminMixin) - Declarative field allowlist (
advanced_search_fields) - Safe parser and strict schema validation
- Nested groups and logical operators
- Support for common Django lookups (
exact,icontains,gt,range,isnull, etc.) - Relation traversal via
__paths - Subquery support (
exists/not_exists) - URL-based query payloads
- Saved query views in admin UI
- Backend-first test coverage
Query Builder Panel
Nested Group Example
Saved Views Dropdown
Installation
Install with whichever tool you use:
pip install django-easy-query-builder
poetry add django-easy-query-builder
uv add django-easy-query-builder
Quick Start
- Add the app to
INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"django_easy_query_builder",
]
- Use the mixin in your admin:
from django.contrib import admin
from django_easy_query_builder.mixins import AdvancedSearchAdminMixin
from .models import Car
@admin.register(Car)
class CarAdmin(AdvancedSearchAdminMixin, admin.ModelAdmin):
advanced_search_fields = [
"model",
"year",
"manufacturer__name",
"manufacturer__country__name",
]
That is enough to enable the query builder UI on that admin changelist.
🎥 Video Tutorial
Configuration
advanced_search_fields
Only fields listed here are queryable. This is the core security boundary.
Examples:
- direct field:
"model" - relation field:
"manufacturer__name" - deep relation field:
"manufacturer__country__name"
advanced_search_lookups (optional)
Default is all supported lookups (["__all__"]).
You can restrict them:
advanced_search_lookups = ["exact", "iexact", "icontains", "gt", "lt"]
URL parameters
- query payload:
advanced_query - saved view selection:
saved_view
Query Payload
The frontend sends a structured JSON payload through advanced_query.
Example:
{
"logicalOperator": "AND",
"conditions": [
{ "field": "manufacturer.country.name", "operator": "equals", "value": "Germany" },
{ "field": "year", "operator": "greater_than", "value": "2018" }
],
"groups": [],
"negated": false
}
The backend parses this payload into a validated query tree, then builds Django Q objects safely.
Security Model
This package is designed as a zero-trust parser:
- no raw SQL
- no
eval - no arbitrary field access
- operator whitelist enforced
- strict schema key validation
- unknown structures rejected early
- ORM-only query construction (
Q,Subquery,OuterRef)
Saved Views
Users can save and reuse advanced queries from admin.
- save endpoint is exposed under admin model URL:
.../save-query/ - payloads are canonicalized and hashed
- duplicate query hashes are deduplicated per model
- usage metadata (
usage_count,last_used_at) is tracked
Development
Install local dependencies and run tests:
pytest -q
Set up pre-commit hooks:
pip install pre-commit
pre-commit install
Project Structure
django_easy_query_builder/package sourcetests/backend and admin integration testsexamples/demo models/admin setup for local testing
Compatibility
- Python 3.10+
- Django 4.2+
License
MIT. See LICENSE.
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_easy_query_builder-0.1.3.tar.gz.
File metadata
- Download URL: django_easy_query_builder-0.1.3.tar.gz
- Upload date:
- Size: 52.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c7ba738a58f2a17911538c1eef735aea8e1439f3e37e18d1dcacd34d6ad3e79
|
|
| MD5 |
b20ce3b261e958712ef365458cd87e5f
|
|
| BLAKE2b-256 |
180bbf756e5cb6445c3b12dc45cd6440798a13857fc3ad6a549dd258019fe8b1
|
Provenance
The following attestation bundles were made for django_easy_query_builder-0.1.3.tar.gz:
Publisher:
publish-pypi.yml on DiyanKalaydzhiev23/django-easy-query-builder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_easy_query_builder-0.1.3.tar.gz -
Subject digest:
1c7ba738a58f2a17911538c1eef735aea8e1439f3e37e18d1dcacd34d6ad3e79 - Sigstore transparency entry: 1091279024
- Sigstore integration time:
-
Permalink:
DiyanKalaydzhiev23/django-easy-query-builder@822aebad268cdebe778f5f9793883fb229b57a74 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/DiyanKalaydzhiev23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@822aebad268cdebe778f5f9793883fb229b57a74 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_easy_query_builder-0.1.3-py3-none-any.whl.
File metadata
- Download URL: django_easy_query_builder-0.1.3-py3-none-any.whl
- Upload date:
- Size: 49.0 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 |
011fc835aa22742c6884c6d34eecd49d91786dd9726b8dbdad7e3d6b9245d814
|
|
| MD5 |
ed2661070a821b762fbe65ffce9f146c
|
|
| BLAKE2b-256 |
99a37eaf67bbcc0c8644069bf87330ffd04384b638bae4ff4048f3435929b0c9
|
Provenance
The following attestation bundles were made for django_easy_query_builder-0.1.3-py3-none-any.whl:
Publisher:
publish-pypi.yml on DiyanKalaydzhiev23/django-easy-query-builder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_easy_query_builder-0.1.3-py3-none-any.whl -
Subject digest:
011fc835aa22742c6884c6d34eecd49d91786dd9726b8dbdad7e3d6b9245d814 - Sigstore transparency entry: 1091279038
- Sigstore integration time:
-
Permalink:
DiyanKalaydzhiev23/django-easy-query-builder@822aebad268cdebe778f5f9793883fb229b57a74 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/DiyanKalaydzhiev23
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@822aebad268cdebe778f5f9793883fb229b57a74 -
Trigger Event:
push
-
Statement type: