2022-01-16 16:13:59 +00:00
|
|
|
from django import forms
|
|
|
|
|
2022-01-30 12:00:58 +00:00
|
|
|
class ProductOneTimeOrderForm(forms.Form):
|
|
|
|
"""
|
|
|
|
For products that only contain onetimeresoures
|
|
|
|
"""
|
|
|
|
|
2022-01-30 09:11:22 +00:00
|
|
|
product = forms.SlugField(required=True, disabled=True)
|
2022-01-16 16:13:59 +00:00
|
|
|
|
|
|
|
def __init__(self, resources, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
for res in resources:
|
|
|
|
print(res)
|
2022-01-30 12:00:58 +00:00
|
|
|
field_name = f"{res.slug}"
|
|
|
|
self.fields[field_name] = forms.FloatField(required=True, label=res.name)
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
cleaned_data = super().clean()
|
|
|
|
print("Cleaning form myself ...")
|
|
|
|
|
|
|
|
|
|
|
|
class ProductOrderForm(ProductOneTimeOrderForm):
|
|
|
|
"""
|
|
|
|
For recurring products (might also have OneTime items
|
|
|
|
"""
|
|
|
|
|
|
|
|
timeframe = forms.SlugField(required=False, disabled=True)
|