A django app to parse queries written outside the django app.
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.
- to write an 'or'
{"or":{"status_id" : 3, "name__icontains":"Ahmed"}}
- to write negation
{"or":{"status_id" : 3, "~name__icontains":"Ahmed"}}
- to write an 'and'
or
{"and":{"status_id" : 3, "name__icontains":"Ahmed"}}
{"status_id" : 3, "name__icontains":"Ahmed"}
pip install django-query-parser
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())
- AND
- OR
- NOT: with a '~' in field name
example
d = {"status": "Completed", "~ordered_by_id": 1}