You have to assign the left side of the comparison to a field name with
annotate. At least I'm not aware of another way, except falling back to raw
SQL.
Assuming VALUE in your example is just a variable:
T.objects.annotate(field_replaced=F('field'), Value('-'), Value(' '),
function='replace')).filter(field_replaced=Func(Value('my_value'),
Value('-'), Value(' '), function='replace'))
This results in a query like this:
SELECT "T"."id", "T"."field", replace("T"."field", '-', ' ') AS
"field_replaced" FROM "T" WHERE replace("T"."field", '-', ' ') =
(replace('my_value', '-', ' '))
Hope that helps!
Daniel
On Thursday, August 24, 2017 at 10:44:40 PM UTC+2, Николай Инкогнито wrote:
>
> SELECT * FROM T WHERE REPLACE(T.field, '-', ' ') = REPLACE(VALUE,'-', ' ')
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/82fde496-2523-4c03-bfa3-5771cb410485%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.