According to the Django documentation, multiple conditions can be used in the when clause.
When(
registered_on__gt=date(2014, 1, 1),
registered_on__lt=date(2015, 1, 1),
then='account_type'
)
However, I am not able to use the same when using Case clause.
Case(
When(
registered_on__gt=date(2014, 1, 1),
registered_on__lt=date(2015, 1, 1),
then='account_type'
),
default='default'
)
I ended up getting the following error:
TypeError: __init__() got multiple values for keyword argument 'then'
Is there any way to do this? Am I missing something here?
1> Ash..:
Maybe the Q expression can help. Try this:
Case(
When(
Q(registered_on__gt=date(2014, 1, 1)) & Q(registered_on__lt=date(2015, 1, 1)),
then='account_type'
),
default='default'
)