Opened 18 months ago

Closed 18 months ago

Last modified 18 months 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 Changed 18 months ago by Simon Charette

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 18 months ago by Tim Graham (previous) (diff)

comment:2 Changed 18 months ago by Nikolas

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 18 months ago by Nikolas (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top