#30061: annotate boolean from a Q object
-------------------------------------+-------------------------------------
     Reporter:  Ryan Hiebert         |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               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 Ryan Hiebert):

 Thank you for letting me know that, Simon. That's such a useful feature,
 that even if using {{{Q}}} objects directly is rejected for some reason
 (though I hope not), it would be very useful to document that it is
 possible to use {{{Q}}} objects in an {{{ExpressionWrapper}}}.

 For anyone that might come across this issue looking for this feature, the
 syntax that currently works and is tested is like this:

 {{{#!python
 notes = notes.filter(user=self.user).annotate(
     is_author=ExpressionWrapper(
         Q(author_id=self.request.user.id),
         output_field=BooleanField(),
     ),
 )
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30061#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 [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/069.7b77713fadc8d9f4368d9b0de8213e11%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to