Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#28527 closed Uncategorized (invalid)

How rewrite query in Django ORM?

Reported by: Nikolas Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

has any way to rewrite in Django ORM?

SELECT * FROM T
WHERE REPLACE(T.field, '-', ' ') = REPLACE(VALUE,'-', ' ')

its possible?
can add this feature or add sample to Docs?

Change History (2)

comment:1 by Simon Charette, 7 years ago

Resolution: invalid
Status: newclosed

Hello Nikolas,

It should be a matter of using annotate() with Func(F('field'), function='REPLACE')) expressions but I don't think we should be documenting every single use of Func.

I suggest you take a look at how you can get support if the documentation isn't enough to help you solve your issue.

Last edited 7 years ago by Tim Graham (previous) (diff)

comment:2 by Nikolas, 7 years ago

i try

obs = Goods.objects\
        .annotate(data2=Func(
                    F('data'),
                    Value("'-'"), Value("' '"),
                    function='replace',

                ))\
        .filter(
            Q(data__contains="Andrew") |
            Q(
                data2=Func(
                    F('data'),
                    Value("'-'"), Value("' '"),
                    function='replace',
                ),
            ))

but cant compare to function (not field), this is not documented, can litle help please?
and i think must be more examples in Docs, complex and big examples, very need.

Thanks for great soft!

Last edited 7 years ago by Nikolas (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top