Skip to main content

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 / NOT groups
  • 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 ModelAdmin mixin (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

Query Builder Panel Placeholder

Nested Group Example

Nested Group Placeholder

Saved Views Dropdown

Saved Views Placeholder

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

  1. Add the app to INSTALLED_APPS:
INSTALLED_APPS = [
    # ...
    "django_easy_query_builder",
]
  1. 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

Watch the 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 source
  • tests/ backend and admin integration tests
  • examples/ 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

django_easy_query_builder-0.1.3.tar.gz (52.0 kB view details)

Uploaded Source

Built Distribution

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

django_easy_query_builder-0.1.3-py3-none-any.whl (49.0 kB view details)

Uploaded Python 3

File details

Details for the file django_easy_query_builder-0.1.3.tar.gz.

File metadata

File hashes

Hashes for django_easy_query_builder-0.1.3.tar.gz
Algorithm Hash digest
SHA256 1c7ba738a58f2a17911538c1eef735aea8e1439f3e37e18d1dcacd34d6ad3e79
MD5 b20ce3b261e958712ef365458cd87e5f
BLAKE2b-256 180bbf756e5cb6445c3b12dc45cd6440798a13857fc3ad6a549dd258019fe8b1

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for django_easy_query_builder-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 011fc835aa22742c6884c6d34eecd49d91786dd9726b8dbdad7e3d6b9245d814
MD5 ed2661070a821b762fbe65ffce9f146c
BLAKE2b-256 99a37eaf67bbcc0c8644069bf87330ffd04384b638bae4ff4048f3435929b0c9

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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