quantity fields in food log and recipe upload drop zone

This commit is contained in:
Joren de Graaf
2026-10-15 20:35:56 +02:00
parent f36f05b9bc
commit 86e3afaca7
25 changed files with 420 additions and 67 deletions
+16
View File
@@ -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