quantity fields in food log and recipe upload drop zone
This commit is contained in:
@@ -149,6 +149,22 @@ class FoodLogForm(forms.ModelForm):
|
||||
return data
|
||||
|
||||
|
||||
class FoodLogEditForm(FoodLogForm):
|
||||
class Meta(FoodLogForm.Meta):
|
||||
fields = FoodLogForm.Meta.fields + ('quantity',)
|
||||
labels = {**FoodLogForm.Meta.labels, 'quantity': 'Quantity (portions)'}
|
||||
widgets = {**FoodLogForm.Meta.widgets,
|
||||
'quantity': forms.NumberInput(attrs={'min': '0.01', 'step': '0.01'})}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
# Older clients may omit the new field; keep the saved quantity in that case.
|
||||
self.fields['quantity'].required = False
|
||||
|
||||
def clean_quantity(self):
|
||||
return self.cleaned_data['quantity'] if self.cleaned_data['quantity'] is not None else self.instance.quantity
|
||||
|
||||
|
||||
class FoodProductHydrationForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = FoodProduct
|
||||
|
||||
Reference in New Issue
Block a user