Recipes phase 3
This commit is contained in:
+21
-4
@@ -4,7 +4,7 @@ from django.core.files.uploadedfile import UploadedFile
|
||||
from PIL import Image, UnidentifiedImageError
|
||||
|
||||
from food.models import FoodProduct
|
||||
from .models import Recipe, RecipeIngredient, RecipeSubrecipe
|
||||
from .models import Recipe, RecipeIngredient, RecipeIngredientSubstitution, RecipeSubrecipe
|
||||
|
||||
|
||||
class RecipeForm(forms.ModelForm):
|
||||
@@ -16,11 +16,13 @@ class RecipeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('title', 'description', 'category', 'preparation_minutes',
|
||||
'cooking_minutes', 'default_servings', 'status', 'parent',
|
||||
'cooking_minutes', 'default_servings', 'yield_amount', 'yield_unit', 'status', 'parent',
|
||||
'instructions_markdown', 'notes_markdown', 'photo')
|
||||
labels = {'instructions_markdown': 'Instructions (Markdown)',
|
||||
'notes_markdown': 'Personal notes (Markdown)',
|
||||
'default_servings': 'Servings', 'parent': 'Variation of'}
|
||||
'default_servings': 'Servings', 'parent': 'Variation of',
|
||||
'yield_amount': 'Recipe yield amount', 'yield_unit': 'Yield unit'}
|
||||
help_texts = {'yield_amount': 'Optional: total cooked weight or volume for using this recipe as a subrecipe.'}
|
||||
widgets = {
|
||||
'description': forms.Textarea(attrs={'rows': 3}),
|
||||
'instructions_markdown': forms.Textarea(attrs={'rows': 10}),
|
||||
@@ -74,9 +76,11 @@ class RecipeForm(forms.ModelForm):
|
||||
class RecipeIngredientForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = RecipeIngredient
|
||||
fields = ('name', 'quantity', 'unit', 'preparation_note', 'is_optional',
|
||||
fields = ('name', 'quantity', 'unit', 'amount_per_unit', 'amount_per_unit_unit',
|
||||
'preparation_note', 'is_optional',
|
||||
'inventory_product', 'nutrition_product', 'display_order')
|
||||
widgets = {'quantity': forms.NumberInput(attrs={'min': '.001', 'step': '.001'}),
|
||||
'amount_per_unit': forms.NumberInput(attrs={'min': '.001', 'step': '.001'}),
|
||||
'display_order': forms.NumberInput(attrs={'min': 0})}
|
||||
|
||||
|
||||
@@ -120,3 +124,16 @@ RecipeSubrecipeFormSet = inlineformset_factory(
|
||||
Recipe, RecipeSubrecipe, form=RecipeSubrecipeForm,
|
||||
formset=OwnedSubrecipeFormSet, fk_name='recipe', extra=1, can_delete=True,
|
||||
)
|
||||
|
||||
|
||||
class RecipeSubstitutionForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = RecipeIngredientSubstitution
|
||||
fields = ('name', 'quantity', 'unit', 'product', 'amount_per_unit',
|
||||
'amount_per_unit_unit', 'display_order')
|
||||
widgets = {'quantity': forms.NumberInput(attrs={'min': '.001', 'step': '.001'}),
|
||||
'amount_per_unit': forms.NumberInput(attrs={'min': '.001', 'step': '.001'})}
|
||||
|
||||
def __init__(self, *args, user, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['product'].queryset = FoodProduct.objects.filter(owner=user).order_by('product_name')
|
||||
|
||||
Reference in New Issue
Block a user