https://github.com/mkalioby/django-query-parser
A django app to store and load partial queries from external sources
https://github.com/mkalioby/django-query-parser
django django-models
Last synced: 3 months ago
JSON representation
A django app to store and load partial queries from external sources
- Host: GitHub
- URL: https://github.com/mkalioby/django-query-parser
- Owner: mkalioby
- License: mit
- Created: 2020-10-26T13:23:49.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-10-28T08:11:53.000Z (over 5 years ago)
- Last Synced: 2026-01-30T16:56:55.979Z (6 months ago)
- Topics: django, django-models
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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'
```python
{"or":{"status_id" : 3, "name__icontains":"Ahmed"}}
```
2. to write negation
```python
{"or":{"status_id" : 3, "~name__icontains":"Ahmed"}}
```
3. to write an 'and'
```python
{"and":{"status_id" : 3, "name__icontains":"Ahmed"}}
```
or
```python
{"status_id" : 3, "name__icontains":"Ahmed"}
```
## Installation
`pip install django-query-parser`
## Example
from test_app
```python
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
```python
d = {"status": "Completed", "~ordered_by_id": 1}
```