53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
from django import forms
|
|
from accounts.models import IAmPrincipalType
|
|
from manage_subscriptions.models import (
|
|
PrincipalSubscription,
|
|
Subscription,
|
|
)
|
|
|
|
class SubscriptionForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Subscription
|
|
fields = [
|
|
"title",
|
|
"short_description",
|
|
"interval",
|
|
"interval_count",
|
|
"high_amount",
|
|
"amount",
|
|
"principal_types",
|
|
"referral_percentage",
|
|
"active",
|
|
"is_free",
|
|
]
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super(SubscriptionForm, self).__init__(*args, **kwargs)
|
|
event_user = IAmPrincipalType.objects.get(name="event_user")
|
|
event_manager = IAmPrincipalType.objects.get(name="event_manager")
|
|
self.fields["principal_types"].queryset = IAmPrincipalType.objects.filter(
|
|
id__in=[event_user.id, event_manager.id]
|
|
)
|
|
|
|
|
|
class PrincipalSubscriptionForm(forms.ModelForm):
|
|
class Meta:
|
|
model = PrincipalSubscription
|
|
fields = [
|
|
"subscription",
|
|
"principal",
|
|
"status",
|
|
"start_date",
|
|
"end_date",
|
|
"grace_period_end_date",
|
|
"comments",
|
|
"coupon_code"
|
|
] # Includes all fields from the model
|
|
widgets = {
|
|
"start_date": forms.DateInput(attrs={"type": "date"}),
|
|
"end_date": forms.DateInput(attrs={"type": "date"}),
|
|
"grace_period_end_date": forms.DateInput(attrs={"type": "date"}),
|
|
}
|
|
|
|
|