blob: c4cdf1a4d2e27dbb4044a42e3f2934426711e0b1 (
plain) (
tree)
|
|
from datetime import timedelta
from allauth.account.signals import user_signed_up
from django.dispatch import receiver
from django.db import transaction
from django.utils import timezone
from .models import SubscriptionPlan, Subscription
@receiver(user_signed_up)
def assign_default_subscription(sender, request, user, **kwargs):
with transaction.atomic():
# Get or create the free plan subscription
free_plan, _ = SubscriptionPlan.objects.get_or_create(
name="Free Plan",
defaults={
"price": 0,
"description": "Free plan description",
"allowed_downloads": 10,
}
)
# Create a SubscriptionPlan for the new user
Subscription.objects.create(
user=user,
plan=free_plan,
is_active=True,
start_date=timezone.now(),
end_date=timezone.now() + timedelta(days=365), # Example: 30 days
)
|