python - Conditional Trial Expiry in Django App -


i'm trying create template-driven expiring trial app , i'm not sure why current method isn't working.

when user signs up, create new customer , current_subscription plan named "free trial":

@receiver(user_signed_up) def create_trial(sender, **kwargs):      user = kwargs['user']     customer = customer.create(user)      fn = settings.trial_period_for_user_callback     days = fn(user)     start = datetime.now()     end = start + timedelta(days=days)     sub = currentsubscription.objects.create(customer=customer,                                              plan="free trial",                                              quantity="1",                                              status='trialing',                                              trial_start=start,                                              trial_end=end,                                              start=start,                                              current_period_end=end,                                              amount=0) 

enter image description here

then have conditional template tag targeting user's plan bring menu telling user trial has expired instead of app:

{% if not current_subscription.plan == 'free trial' or current_subscription.is_valid %} # trial expiry stuff {% endif %} 

but when trial's expired , plan's value != 'free trial' in db conditional isn't evaluating correctly. tag wrong? thanks

the condition evaluate incorrect, because suppose not applied 2 conditions. (while applied boolean test directly follows it)

you have problem is_valid method. (post code can check out)

here's correct conditional statement:

{% if current_subscription.plan != 'free trial' or not current_subscription.is_valid %} # trial expiry stuff {% endif %} 

that should work better.


Comments