#24386: Querysets with filters and exclusions based on deep relations build 
invalid
queries
-------------------------------------+-------------------------------------
     Reporter:  rtpg                 |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  1                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by rtpg):

 I don't know if annotations allow me to work around this. I need to find
 the minimum of only active employees, but to my knowledge the aggregates
 don't really work in combination with filters:

 I added a {{{number}}} field to my Employee model:

 {{{
 In [5]: Employee.objects.annotate(Sum('owner__employee__number')).values()
 Out[5]: [{'status': u'not_active', 'number': 3, u'id': 2,
 'owner__employee__number__sum': 7, 'start_date': datetime.date(2015, 2,
 23), u'owner_id': 1}, {'status': u'active', 'number': 4, u'id': 1,
 'owner__employee__number__sum': 7, 'start_date': datetime.date(2015, 2,
 23), u'owner_id': 1}]

 In [6]:
 
Employee.objects.filter(number=4).annotate(Sum('owner__employee__number')).values()
 Out[6]: [{'status': u'active', 'number': 4, u'id': 1,
 'owner__employee__number__sum': 7, 'start_date': datetime.date(2015, 2,
 23), u'owner_id': 1}]
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24386#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.23d25828da432fccff467a64168a44ce%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to