complete rework of offerings

This commit is contained in:
Tobias Brunner 2025-02-28 14:13:51 +01:00
parent 84e25c82d1
commit 20f27bd6b5
No known key found for this signature in database
16 changed files with 313 additions and 294 deletions

View file

@ -1,5 +1,5 @@
from django import forms
from .models import Lead, Plan, PlanPrice
from .models import Lead, Plan
class LeadForm(forms.ModelForm):
@ -18,33 +18,8 @@ class LeadForm(forms.ModelForm):
class PlanForm(forms.ModelForm):
class Meta:
model = Plan
fields = ("name", "description", "is_default", "features", "order")
fields = ("name", "description")
widgets = {
"description": forms.Textarea(attrs={"rows": 3}),
"features": forms.Textarea(attrs={"rows": 4}),
}
def clean(self):
cleaned_data = super().clean()
# If this is set as default, ensure no other plan for this service is default
if cleaned_data.get("is_default"):
service = self.instance.service
if service:
Plan.objects.filter(service=service).exclude(
pk=self.instance.pk
).update(is_default=False)
return cleaned_data
class PlanPriceForm(forms.ModelForm):
class Meta:
model = PlanPrice
fields = ("currency", "price")
def clean(self):
cleaned_data = super().clean()
currency = cleaned_data.get("currency")
price = cleaned_data.get("price")
if price and price < 0:
raise forms.ValidationError("Price cannot be negative")
return cleaned_data