Code Monkey home page Code Monkey logo

django-find's Introduction

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

django-find's People

Contributors

knipknap avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.