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.2.tar.gz (17.8 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.2-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_find-1.0.2.tar.gz
  • Upload date:
  • Size: 17.8 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.2.tar.gz
Algorithm Hash digest
SHA256 2332dfe026f2d589bc19ae0d9e0da355129db326cfd463b344bd58d5d3289493
MD5 8cdf30c9709b7e4c6566f6ba3bac51f0
BLAKE2b-256 b371159f49ae9d3288e4c481a104e8fe930cf9cc8d6e86ddf5d43f1239f08e54

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: django_find-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 24.3 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5bf94e4d98f7526fa77ac6f707dde091b942f0ca9d814ffed0f760248dc196ec
MD5 75b44644ff33e695fcf9ea68b9ffa558
BLAKE2b-256 1aaee2daed7c5af44a9a29e8d8103864002f0cb55a5cbd10758852b656c04ee8

See more details on using hashes here.

Provenance

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