From 5b2fd176da8c197730dbd538a0f491972acc7e74 Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Wed, 19 Feb 2020 13:37:18 +0100 Subject: [PATCH] Added constraints to many to many tables --- .../migrations/0002_auto_20200219_1336.py | 25 +++++++++++++++++++ food_planner/models.py | 3 +++ 2 files changed, 28 insertions(+) create mode 100644 food_planner/migrations/0002_auto_20200219_1336.py diff --git a/food_planner/migrations/0002_auto_20200219_1336.py b/food_planner/migrations/0002_auto_20200219_1336.py new file mode 100644 index 0000000..15b34ad --- /dev/null +++ b/food_planner/migrations/0002_auto_20200219_1336.py @@ -0,0 +1,25 @@ +# Generated by Django 3.0.3 on 2020-02-19 12:36 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('food_planner', '0001_initial'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='storedingredient', + unique_together={('pantry', 'ingredient')}, + ), + migrations.AlterUniqueTogether( + name='usedingredient', + unique_together={('recipe', 'ingredient')}, + ), + migrations.AlterUniqueTogether( + name='usedkitchenutility', + unique_together={('recipe', 'kitchen_utility')}, + ), + ] diff --git a/food_planner/models.py b/food_planner/models.py index 34d2537..2d7a29e 100644 --- a/food_planner/models.py +++ b/food_planner/models.py @@ -122,6 +122,7 @@ class UsedKitchenUtility(models.Model): default=1) class Meta: + unique_together = ['recipe', 'kitchen_utility'] verbose_name = _('Used kitchen utility') verbose_name_plural = _('Used kitchen utilities') @@ -134,6 +135,7 @@ class UsedIngredient(models.Model): unit = models.CharField(_('Unit for amount'), max_length=10, choices=MEASUREMENT_UNITS) class Meta: + unique_together = ['recipe', 'ingredient'] verbose_name = _('Used ingredient') verbose_name_plural = _('Used ingredients') @@ -190,6 +192,7 @@ class StoredIngredient(models.Model): choices=MEASUREMENT_UNITS) class Meta: + unique_together = ['pantry', 'ingredient'] verbose_name = _('Stored ingredient') verbose_name_plural = _('Stored ingredients')