#24833: Annotation with `Case` can't be used with `exclude`
----------------------------------------------+--------------------
     Reporter:  coolRR                        |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.8
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 n use `.filter` on it but you can't use `.exclude`. (You get various
 exceptions about `.null` and `.get_col` not existing.)

 Example:

 {{{
 def my_view(request, *args, **kwargs):
     things = models.Thing.objects.all().annotate(
         bar=django.db.models.Case(
             django.db.models.When(
                 foo='foo',
                 then=django.db.models.Value('bar')
             ),
             default=django.db.models.Value('baz'),
             output_field=django.db.models.CharField()
         )
     )

     print(things.filter(bar='bar')) # This one works
     print(things.exclude(bar='bar')) # This one doesn't
     return django.http.HttpResponse(str(things))
 }}}

 Full working example attached to this ticket. (Simply run `migrate`, then
 `runserver`, then access the root URL to see the Django debug page for the
 exception.)

--
Ticket URL: <https://code.djangoproject.com/ticket/24833>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.df7ca19e7869da5369ed749c8b2e09fb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to