From 8ff52f542e7fd3c1d3e50b5c26a594965b084f97 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Thu, 11 Jun 2020 22:32:45 +0200 Subject: [PATCH] ingredient rounding upgrades --- cookbook/forms.py | 3 ++- ...0052_userpreference_ingredient_decimals.py | 18 ++++++++++++++++++ .../migrations/0053_auto_20200611_2217.py | 18 ++++++++++++++++++ cookbook/models.py | 3 ++- cookbook/templates/recipe_view.html | 19 +++++++++++++------ cookbook/views/views.py | 1 + 6 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 cookbook/migrations/0052_userpreference_ingredient_decimals.py create mode 100644 cookbook/migrations/0053_auto_20200611_2217.py diff --git a/cookbook/forms.py b/cookbook/forms.py index 3ea81f9d0..c9d1aad73 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -31,13 +31,14 @@ class UserPreferenceForm(forms.ModelForm): class Meta: model = UserPreference - fields = ('default_unit', 'theme', 'nav_color', 'default_page', 'show_recent', 'search_style', 'plan_share') + fields = ('default_unit', 'theme', 'nav_color', 'default_page', 'show_recent', 'search_style', 'plan_share', 'ingredient_decimals') help_texts = { 'nav_color': _('Color of the top navigation bar. Not all colors work with all themes, just try them out!'), 'default_unit': _('Default Unit to be used when inserting a new ingredient into a recipe.'), 'plan_share': _('Default user to share newly created meal plan entries with.'), 'show_recent': _('Show recently viewed recipes on search page.'), + 'ingredient_decimals': _('Number of decimals to round ingredients.') } widgets = { diff --git a/cookbook/migrations/0052_userpreference_ingredient_decimals.py b/cookbook/migrations/0052_userpreference_ingredient_decimals.py new file mode 100644 index 000000000..14a7ee7d0 --- /dev/null +++ b/cookbook/migrations/0052_userpreference_ingredient_decimals.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-06-11 20:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0051_auto_20200611_1518'), + ] + + operations = [ + migrations.AddField( + model_name='userpreference', + name='ingredient_decimals', + field=models.IntegerField(default=2), + ), + ] diff --git a/cookbook/migrations/0053_auto_20200611_2217.py b/cookbook/migrations/0053_auto_20200611_2217.py new file mode 100644 index 000000000..976c5817a --- /dev/null +++ b/cookbook/migrations/0053_auto_20200611_2217.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-06-11 20:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0052_userpreference_ingredient_decimals'), + ] + + operations = [ + migrations.AlterField( + model_name='recipeingredient', + name='amount', + field=models.DecimalField(decimal_places=16, default=0, max_digits=32), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index a3609f5c2..98ae4578b 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -63,6 +63,7 @@ class UserPreference(models.Model): search_style = models.CharField(choices=SEARCH_STYLE, max_length=64, default=LARGE) show_recent = models.BooleanField(default=True) plan_share = models.ManyToManyField(User, blank=True, related_name='plan_share_default') + ingredient_decimals = models.IntegerField(default=2) def __str__(self): return str(self.user) @@ -163,7 +164,7 @@ class RecipeIngredient(models.Model): recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.PROTECT) unit = models.ForeignKey(Unit, on_delete=models.PROTECT) - amount = models.DecimalField(default=0, decimal_places=2, max_digits=16) + amount = models.DecimalField(default=0, decimal_places=16, max_digits=32) note = models.CharField(max_length=64, null=True, blank=True) def __str__(self): diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index 9f577c94e..ceab46198 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -327,6 +327,8 @@