From ce27ae88f18b9b4059eaa08856dff763b2b4f73f Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Fri, 15 Nov 2019 15:00:25 +0100 Subject: [PATCH] time --- cookbook/forms.py | 8 +++++--- cookbook/migrations/0011_recipe_time.py | 19 +++++++++++++++++++ cookbook/models.py | 1 + cookbook/templates/recipe_view.html | 6 ++++++ cookbook/views/edit.py | 1 + 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 cookbook/migrations/0011_recipe_time.py diff --git a/cookbook/forms.py b/cookbook/forms.py index 291b2a8c..b5dca725 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -22,11 +22,12 @@ class ExternalRecipeForm(forms.ModelForm): class Meta: model = Recipe - fields = ('name', 'keywords', 'file_path', 'storage', 'file_uid') + fields = ('name', 'keywords', 'time', 'file_path', 'storage', 'file_uid') labels = { 'name': _('Name'), 'keywords': _('Keywords'), + 'time': _('Preparation time in minutes'), 'file_path': _('Path'), 'file_uid': _('Storage UID'), } @@ -36,12 +37,13 @@ class ExternalRecipeForm(forms.ModelForm): class InternalRecipeForm(forms.ModelForm): class Meta: model = Recipe - fields = ('name', 'instructions', 'keywords') + fields = ('name', 'instructions', 'time', 'keywords') labels = { 'name': _('Name'), 'keywords': _('Keywords'), 'instructions': _('Instructions'), + 'time': _('Preparation time in minutes'), } widgets = {'keywords': MultiSelectWidget} @@ -49,7 +51,7 @@ class InternalRecipeForm(forms.ModelForm): class CommentForm(forms.ModelForm): class Meta: model = Comment - fields = ('text', ) + fields = ('text',) labels = { 'text': _('Add your comment: '), diff --git a/cookbook/migrations/0011_recipe_time.py b/cookbook/migrations/0011_recipe_time.py new file mode 100644 index 00000000..d777bdc6 --- /dev/null +++ b/cookbook/migrations/0011_recipe_time.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.7 on 2019-11-15 13:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0010_recipe_internal'), + ] + + operations = [ + migrations.AddField( + model_name='recipe', + name='time', + field=models.IntegerField(blank=True, default=0), + preserve_default=False, + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index dc872194..c3347fbd 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -61,6 +61,7 @@ class Recipe(models.Model): file_path = models.CharField(max_length=512, default="") link = models.CharField(max_length=512, default="") keywords = models.ManyToManyField(Keyword, blank=True) + time = models.IntegerField(blank=True) internal = models.BooleanField(default=False) created_by = models.ForeignKey(User, on_delete=models.PROTECT) created_at = models.DateTimeField(auto_now_add=True) diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index 09b7fa57..452599e0 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -25,6 +25,12 @@
{% endif %} + {% if recipe.time and recipe.time != 0 %} + {% trans 'Preparation time ca.' %} {{ recipe.time }} min +
+
+ {% endif %} + {% if ingredients %}
diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py index 131871ee..d5a000f0 100644 --- a/cookbook/views/edit.py +++ b/cookbook/views/edit.py @@ -39,6 +39,7 @@ def internal_recipe_update(request, pk): recipe = recipe_instance recipe.name = form.cleaned_data['name'] recipe.instructions = form.cleaned_data['instructions'] + recipe.time = form.cleaned_data['time'] recipe.save()