from django import forms from .models import FoodProduct, Unit class ManualFoodForm(forms.ModelForm): class Meta: model = FoodProduct fields = ('product_name', 'brand', 'base_unit', 'energy_kcal_100', 'carbohydrates_100', 'protein_100', 'fat_100', 'fibre_100', 'sugars_100', 'salt_100') labels = { 'energy_kcal_100': 'Calories per 100 g or ml', 'carbohydrates_100': 'Carbohydrates per 100 g or ml', 'protein_100': 'Protein per 100 g or ml', 'fat_100': 'Fat per 100 g or ml', } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) for field in ('energy_kcal_100', 'carbohydrates_100', 'protein_100', 'fat_100'): self.fields[field].required = True