Add serving count to recipe

This commit is contained in:
tourn 2020-08-30 15:59:25 +02:00
parent 82497c734a
commit 652b4bf2af
6 changed files with 34 additions and 5 deletions

View File

@ -84,13 +84,14 @@ class InternalRecipeForm(forms.ModelForm):
class Meta:
model = Recipe
fields = ('name', 'image', 'working_time', 'waiting_time', 'keywords')
fields = ('name', 'image', 'working_time', 'waiting_time', 'servings', 'keywords')
labels = {
'name': _('Name'),
'keywords': _('Keywords'),
'working_time': _('Preparation time in minutes'),
'waiting_time': _('Waiting time (cooking/baking) in minutes'),
'servings': _('Number of servings'),
}
widgets = {'keywords': MultiSelectWidget}

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-08-30 13:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cookbook', '0074_remove_keyword_created_by'),
]
operations = [
migrations.AddField(
model_name='recipe',
name='servings',
field=models.IntegerField(default=1),
),
]

View File

@ -175,6 +175,7 @@ class Step(models.Model):
class Recipe(models.Model):
name = models.CharField(max_length=128)
servings = models.IntegerField(default=1)
image = models.ImageField(upload_to='recipes/', blank=True, null=True)
storage = models.ForeignKey(Storage, on_delete=models.PROTECT, blank=True, null=True)
file_uid = models.CharField(max_length=256, default="", blank=True)

View File

@ -139,7 +139,7 @@ class RecipeSerializer(WritableNestedModelSerializer):
class Meta:
model = Recipe
fields = ['id', 'name', 'image', 'keywords', 'steps', 'working_time', 'waiting_time', 'created_by', 'created_at', 'updated_at', 'internal']
fields = ['id', 'name', 'image', 'keywords', 'steps', 'working_time', 'waiting_time', 'servings', 'created_by', 'created_at', 'updated_at', 'internal']
read_only_fields = ['image', 'created_by', 'created_at']

View File

@ -62,6 +62,9 @@
<label for="id_name"> {% trans 'Waiting Time' %}</label>
<input class="form-control" id="id_wait_time" v-model="recipe.waiting_time">
<br/>
<label for="id_name"> {% trans 'Servings' %}</label>
<input class="form-control" id="id_servings" v-model="recipe.servings">
<br/>
<label for="id_name"> {% trans 'Keywords' %}</label>
<multiselect
v-model="recipe.keywords"

View File

@ -107,7 +107,7 @@
<div class="input-group d-print-none">
<input type="number" value="1" maxlength="3" class="form-control"
v-model="ingredient_factor"/>
v-model="servings"/>
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-calculator"></i></span>
</div>
@ -448,6 +448,8 @@
let csrftoken = Cookies.get('csrftoken');
Vue.http.headers.common['X-CSRFToken'] = csrftoken;
const recipe_servings = {{ recipe.servings }}
let app = new Vue({
delimiters: ['[[', ']]'],
el: '#id_base_container',
@ -455,9 +457,13 @@
recipe: undefined,
has_ingredients: false,
has_times: false,
ingredient_factor: 1,
servings: recipe_servings,
},
computed: {
ingredient_factor: function () {
return this.servings / recipe_servings
}
},
mounted: function () {
this.loadRecipe()
},