#29291: Conditional expressions and ~Q queries
-------------------------------------+-------------------------------------
Reporter: Bo Marchman | 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: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Can Sarıgöl):
as I can see, the problem is null db objects can use in where clause
properly. If your columns is nullable, you have to manage it when you use
in select or where clauses. q1 query might be changed like this:
{{{
qs1 = Application.objects.annotate(
needs_review=Case(
When(~Q(Q(score__reviewed=True) |
Q(score__reviewed__isnull=False)), then=V(True)),
default=V(False),
output_field=BooleanField()
)
).filter(needs_review=True)
}}}
if we want to make a query like q2, it could be like this:
{{{
qs1 = Application.objects.filter(
~Q(id__in=Score.objects.annotate(
needs_review = Case(
When(Q(reviewed=True) | Q(reviewed__isnull=False),
then=F('application_id')),
output_field=IntegerField()
)
).values_list('needs_review', flat=True))
)
}}}
at this case, we can get rid of the score table's column or join query.
--
Ticket URL: <https://code.djangoproject.com/ticket/29291#comment:6>
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/062.8b145928c031b9428264cfcef465e03c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.