Skip to content

mkalioby/django-query-parser

Repository files navigation

django-query-parser

A django app to parse queries written outside the django app.

Idea

Some queries are controls the business case, so it will be benefical if they are can saved outside the application like in a config file or a database so the logic can be changed without changing the code.

Samples

  1. to write an 'or'
     {"or":{"status_id" : 3, "name__icontains":"Ahmed"}}
  2. to write negation
    {"or":{"status_id" : 3, "~name__icontains":"Ahmed"}}
  3. to write an 'and'
     {"and":{"status_id" : 3, "name__icontains":"Ahmed"}}
    or
    {"status_id" : 3, "name__icontains":"Ahmed"}

Installation

pip install django-query-parser

Example

from test_app

from query_parser.Parser import  Parse
d = {"or": {
   "status": "Completed",
   "ordered_by_id": 2
   }}
res = Parse(d)
print(Order.objects.filter(res).count())

Operation Supported

  1. AND
  2. OR
  3. NOT: with a '~' in field name example
    d = {"status": "Completed", "~ordered_by_id": 1}

About

A django app to store and load partial queries from external sources

Topics

Resources

License

Stars

Watchers

Forks