my subscriptions page 11

This commit is contained in:
rizwanisready
2024-08-12 20:47:36 +05:30
parent cfff16393f
commit 8f59f81796
3 changed files with 19 additions and 1 deletions

View File

@@ -46,6 +46,19 @@ class SubscriptionForm(forms.ModelForm):
id__in=[event_user.id, event_manager.id]
)
def clean(self):
cleaned_data = super().clean()
stripe_product = cleaned_data.get("stripe_product")
if not stripe_product:
self.add_error(
"stripe_product",
"Please select a Stripe product to create a subscription.",
)
return cleaned_data
class PrincipalSubscriptionForm(forms.ModelForm):
class Meta:

View File

@@ -77,6 +77,12 @@ class Subscription(BaseModel):
{"high_amount": "High amount must be greater than amount."}
)
# Ensure stripe_product is compulsory present
# if not self.stripe_product:
# raise ValidationError(
# {"stripe_product": "Please select stripe product to create subscription."}
# )
def save(self, *args, **kwargs):
self.clean() # Call clean before saving to ensure validation
super().save(*args, **kwargs)