Tuesday, November 29, 2016

Re: rewrite PostgreSQL query to Django ORM

I think you would still need some SQL, you could use annotate to add the field with the value of the calculation and then add .order_by() to the queryset


On Tue, Nov 29, 2016 at 11:07 PM, Artem Bernatskyy <artem.bernatskyy@gmail.com> wrote:
Hello, how to rewrite this PostgreSQL query to Django ORM with no raw SQL ?


select * from finance_fund order by((select price from finance_nav where date='2016-11-08' and fund_id=finance_fund.id)/(select price from finance_nav where date='2016-11-07' and fund_id=finance_fund.id)) LIMIT 30;

So basically i need to order by division result of two simple queries of backward relations of Foreign key

Thanks in advance !

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/9fbf9c99-c914-437b-aae2-a366a0f8eaec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/CAFWa6t%2BRu7AtgDdmAA36E2G7K80VfxXG7ZFy5n30gDwAtU%3DWxg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment