Skip to content

jlubcke/tri.query

Repository files navigation

image

image

Warning

tri.query is end of life. It has been merged into iommi.

iommi is backwards incompatible but the porting effort should be fairly mild, the biggest changes are that show is now called include, Variable is renamed to Filter and plural is used consistently for containers (so variable__foo is filters__foo in iommi).

tri.query

tri.query makes it easy to implement searching and filtering in your Django app.

Major features:

  • Generate simple filtering GUIs easily while at the same time:
  • Supply your views with advanced query languages
  • Query language can be used stand alone without the GUI parts
  • Highly customizable GUI based on tri.form

Example

Simple view that allows the user to search for a car by choosing the make from a drop down, and search for specific model in the advanced mode:

class CarQuery(Query):
    make = Variable.choice(
        choices=['Toyota', 'Volvo', 'Ford'],
        form_field__show=True)  # Display this field in the simple style GUI
    model = Variable.text()

def cars(request):
    query = CarQuery()
    cars_query_set = query.request_to_q(request)
    form = query.form()
    return render(
        template_name='cars.html',
        context_instance=RequestContext(request, {'query_form': form, 'cars': cars_query_set}))
<!-- cars.html -->
{% include "tri_query/form.html" with form=query_form %}

<ul>
    {% for car in cars %}
        <li>{{ car }}</li>
    {% endfor %}
</ul>

image

After switching to the advanced mode:

image

Programmatically call the search API:

query = CarQuery()
cars_query_set = query.parse('make=Toyota and (make=1991 or make=1992)')

Running tests

You need tox installed then just make test.

License

BSD

Documentation

http://triquery.readthedocs.org

About

tri.query makes it easy to implement searching and filtering in your Django app

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •