Skip to main content

Simple but powerful search/filter functionality for Django projects

Project description

django-find

Build Status Coverage Status Code Climate Documentation Status

Summary

django-find is a Django app that makes it easy to add complex search/filter functionality for the models in your project. It supports two different ways to search your Django models: Query-based, or JSON-based.

django-find is not a full text search engine, it searches the fields of your models. In other words, it filters on your models and provides tabular data as a result.

Features

Query-based search

By query-based, we mean that you can use statements like these to search your models:

author:"robert frost" and (title:road or chapter:2)

Add a search field to your template using a single tag

{% load find_tags %}
{% find object_list %}
{% for obj in object_list %}
  {{ obj.name }}
{% endfor %}

(object_list is a queryset that is passed to the template)

Query in your code

Just add the Searchable mixin:

from django_find import Searchable

class Author(models.Model, Searchable):
    name = models.CharField("Author Name", max_length=10)
    ...

And you are good to go:

# Query-based search returns a standard Django QuerySet that you
# can .filter() and work with as usual.
query = Book.by_query('author:"robert frost" and title:"the road"')

# You can also get a Django Q object for the statements.
q_obj = Book.q_from_query('author:"robert frost" and title:"the road"')

Query using JSON

To make it easy to do complex searches spanning multiple models, JSON-based query method is provided. It allows your to make custom searches like these:

Custom Search

For this, a JSON-based search functionality is provided:

{
    "Author":{"name":[[["equals","test"]]]},
    "Book": {"title":[[["notcontains","c"]]]},
    "Chapter": {"content":[[["startswith","The "]]]}
}

django-find is smart in figuring out how to join those models together and return a useful result. In your code, you can load the JSON and get back the search result:

# JSON-based search exhausts what Django's ORM can do, so it does
# not return a Django QuerySet, but a row-based PaginatedRawQuerySet:
query, field_list = Book.by_json_raw('''{
    "Chapter": {"title":[[["contains","foo"]]]}
}''')
print('|'.join(field_list))
for row in query:
    print('|'.join(row))

Documentation

Full documentation, including installation instructions, is here:

http://django-find.readthedocs.io

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_find-1.0.1.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

django_find-1.0.1-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file django_find-1.0.1.tar.gz.

File metadata

  • Download URL: django_find-1.0.1.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_find-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7a7131e700afac734da4b43da069a0bfcb16f5f2cbb3f006a768e62c6460c1d4
MD5 ae215df0a0ccad6fee6bb048a2c1005d
BLAKE2b-256 f7a2fb2034ec183129214ca06024268caa30b2d95abc35d138bc33c77f770b22

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_find-1.0.1.tar.gz:

Publisher: publish.yml on knipknap/django-find

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_find-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_find-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_find-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2c40deaff9820ac81eea72ac251afa9594fa7ee72d246cf710aa972531ef89c4
MD5 71d8694a62fd4b8d12bae0d052cbd9c2
BLAKE2b-256 0a11f65fed77180072b9768a977242b499516d79d1a073afbc31084738f89c3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_find-1.0.1-py3-none-any.whl:

Publisher: publish.yml on knipknap/django-find

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