mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #31606 -- Allowed using condition with lookups in When() expression.
This commit is contained in:
committed by
Mariusz Felisiak
parent
2aac176e86
commit
587b179d41
@@ -876,8 +876,11 @@ class When(Expression):
|
||||
conditional = False
|
||||
|
||||
def __init__(self, condition=None, then=None, **lookups):
|
||||
if lookups and condition is None:
|
||||
condition, lookups = Q(**lookups), None
|
||||
if lookups:
|
||||
if condition is None:
|
||||
condition, lookups = Q(**lookups), None
|
||||
elif getattr(condition, 'conditional', False):
|
||||
condition, lookups = Q(condition, **lookups), None
|
||||
if condition is None or not getattr(condition, 'conditional', False) or lookups:
|
||||
raise TypeError(
|
||||
'When() supports a Q object, a boolean expression, or lookups '
|
||||
|
||||
Reference in New Issue
Block a user