Arnaldo Díaz Molina
2018-12-05 16:10:31 UTC
Hello and thanks in advanced,
I am using Django 1.11 ORM. I need to make this SQL query:
SELECT model1.field1, sum(model2.field1), sum(model2.field2)
FROM
model1
LEFT JOIN model2 on model2.model1_id=model1.id and model2.date='2018-12-02'
group by model1.field1
I have used annotations for this kind of queries and works well when no
needed of extra conditions in left join clause.
But in this case, I need an extra condition inside left join.
How to write this using Django ORM??? Raw queries can be used, but It seems
very strange that ORM can not do this in an easy way.
Thanks again,
Arnaldo.
I am using Django 1.11 ORM. I need to make this SQL query:
SELECT model1.field1, sum(model2.field1), sum(model2.field2)
FROM
model1
LEFT JOIN model2 on model2.model1_id=model1.id and model2.date='2018-12-02'
group by model1.field1
I have used annotations for this kind of queries and works well when no
needed of extra conditions in left join clause.
But in this case, I need an extra condition inside left join.
How to write this using Django ORM??? Raw queries can be used, but It seems
very strange that ORM can not do this in an easy way.
Thanks again,
Arnaldo.
--
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+***@googlegroups.com.
To post to this group, send email to django-***@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/5700f3f4-de27-4ed9-99e3-85f83f064751%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+***@googlegroups.com.
To post to this group, send email to django-***@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/5700f3f4-de27-4ed9-99e3-85f83f064751%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.