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

Screenshots (Placeholders)

Replace these placeholders with your real screenshots.

Query Builder Panel

Query Builder Panel Placeholder

Placeholder: main changelist page with query builder UI.

Nested Group Example

Nested Group Placeholder

Placeholder: example with nested AND / OR groups and relation filters.

Saved Views Dropdown

Saved Views Placeholder

Placeholder: saved query selection and apply flow.

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.

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.0.tar.gz (50.3 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.0-py3-none-any.whl (47.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for django_easy_query_builder-0.1.0.tar.gz
Algorithm Hash digest
SHA256 04d0dba37c321a36763007784563caa67576079fc8b199709a965d14329e8b2a
MD5 14cbbcb8b93ca1d53cc52292b0ae9e32
BLAKE2b-256 07e882a9b2e6cf904288985d3d967d3a991ee14c37709d0e152840bfdfcfabff

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_easy_query_builder-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_easy_query_builder-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee22852e3ab48db66925f9b9ab1fe857354d4db3ad1028308197190fb6926221
MD5 a9b6c6913c4fe33a27a0e1c589fe4ee3
BLAKE2b-256 41ac5fbe871cd9d8ff161c936f39c5f7f81dc9b43a05a13cf9e273e36c0aac74

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_easy_query_builder-0.1.0-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