Do not allow to choose resource unit when min == max
This commit is contained in:
parent
ee3b20227e
commit
8668e173b9
|
@ -1,4 +1,6 @@
|
|||
from django import forms
|
||||
from django.forms import NumberInput
|
||||
|
||||
|
||||
class ProductOneTimeOrderForm(forms.Form):
|
||||
"""
|
||||
|
@ -12,7 +14,15 @@ class ProductOneTimeOrderForm(forms.Form):
|
|||
for res in resources:
|
||||
print(res)
|
||||
field_name = f"{res.slug}"
|
||||
self.fields[field_name] = forms.FloatField(required=True, label=res.name)
|
||||
if res.minimum_units < res.maximum_units:
|
||||
self.fields[field_name] = forms.FloatField(
|
||||
required=True,
|
||||
label=res.name,
|
||||
min_value=res.minimum_units,
|
||||
max_value=res.maximum_units,
|
||||
widget=NumberInput(attrs={"step": res.step_size}))
|
||||
else:
|
||||
self.fields[field_name] = forms.FloatField(widget=forms.HiddenInput(attrs={'value': res.minimum_units}))
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
|
|
Loading…
Reference in New Issue