B
B
bodrich2021-03-24 13:26:35
Django
bodrich, 2021-03-24 13:26:35

How to pass boolean expression through Django to db?

There is a model A with fields b, c, d (let everything be text fields).
There is an action in the view that takes a logical expression as input, for example:

(b = 'test1' and c = 'test2') or d = 'test3'

The logical expression can be anything. How to filter model A by a given expression?
You can just substitute it in raw SQL code, but then it's an open SQL injection.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antonio Solo, 2021-03-24
@solotony

1) validate what was sent to you
2) make a constructor for DNF or CNF

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question