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.3.tar.gz (18.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.3-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for django_find-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b052c9318c6824bcc18019d0f7c31fc568ebdcfbdbd01b86e41150fd393f88c0
MD5 2e0ad00ee980d5f94ecf99506c0771ee
BLAKE2b-256 1427c99acf8b3a54a3282b53e096b7f71b1f1f9f19ea97bfd8c029f48a876182

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_find-1.0.3.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.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for django_find-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f628da29430eb9f9e7635aaab29f22f5c02af9ca185bdd1e69c9973d59e42714
MD5 da6751983a81ee0fa6ecdadee8ae8c31
BLAKE2b-256 4b98838bc2ddeffffcbf8041d2511b9f8fefee0c2e47a740058ef121e7910536

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_find-1.0.3-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