I am working on a Django application. I need to include subscription service in the application. I am using the fields is_subscribed
, subscription_start
and subscription_end
in the user profile
models. I am using Razorpay for the payment integration. After successful payment I am updating the subscription status as follows:
UserProfile.objects.filter(user=request.user).update(is_subscribed=True,subscription_start=datetime.datetime.now(),subscription_end=datetime.datetime.now()+datetime.timedelta(days))
How to update the UserProfile
automatically as soon the subscription_end
is less than the current time. I want the model to be updated as is_subscribed
as False as soon as the time is over. As of now, whenever a user visits any url, I am checking whether the user's subscription is valid. If not , then I am updating the model in this way
user = UserProfile.objects.filter(user=request.user).values()
use1 = UserProfile.objects.filter(user=request.user,subscription_end__gte=datetime.datetime.now()).values()
if not use1[0]['is_admin']:
UserProfile.objects.filter(user=request.user).update(is_subscribed=False,joined=[])
. what is the correct way to update as soon as the subscription ends.