Hello,
Here is a table "myTable" with columns of "col1", "col2", "col3", ..., "col5". The types of these columns are all float. Now for two values from any two columns of these columns, I may need to add, or subtract, or multiply or divide these two values. With this result, I do a condition check.
For example, I want to retrieve all objects that meet "col1_value / col2_value >= 2.0". How to create such a filter?
I do not know which columns' values to use; all I know is that they are represented with variables. These variables are
col_var_1, condition_operator, col_var_2, manipulation_operator, constant_value
where: col_var_1: col1, or col2, or col3, etc
condition_operator: >, >=, <, =, etc
col_var_2: col1, or col2, etc
manipulation_operator: +, -, x, /
constant_value: float value
I know that this is the right syntax:
results = MyFoo.objects.extra(where=[ "col1_value >= col2_value * 2", ])
The problem is that I only know variables instead of values. For example, "col1_value" is saved in "col_var_1".
So the where clause is:
col_var_1 condition_operator col_var_2 manipulation_operator constant_value
Anybody knows how to handle this?
Thanks so much.