mirror of
https://github.com/django/django.git
synced 2025-08-31 07:47:37 +00:00
Fixed #31606 -- Allowed using condition with lookups in When() expression.
This commit is contained in:
parent
2aac176e86
commit
587b179d41
4 changed files with 26 additions and 3 deletions
|
@ -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 '
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue