#32717: Incorrect SQL generation filtering OR-combined queries
-------------------------------------+-------------------------------------
     Reporter:  Shaheed Haque        |                    Owner:  Simon
                                     |  Charette
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Release blocker      |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 To answer your initial question though your query would likely be more
 easily expressed using `Q`

 {{{#!python
 def jurisdiction_qs(for_jurisdiction):
     filter_ = Q(jurisdiction=for_jurisdiction)
     if for_jurisdiction != 'Universal':
         filter_ |= Q(jurisdiction='Universal') & ~Q(
             name__in=Buss.objects.filter(filter_).values_list('name',
 flat=True)
         )
     if for_jurisdiction != 'Company':
        filter_ |= Q(jurisdiction='Company') & ~Q(
             name__in=Buss.objects.filter(filter_).values_list('name',
 flat=True)
         )
     return Buss.objects.filter(filter_)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32717#comment:7>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/070.32cee26546bb4d9ad799def3ce76e591%40djangoproject.com.

Reply via email to