From 968fa64d37dba598abb4331b0036bce84e6a01fb Mon Sep 17 00:00:00 2001 From: quark Date: Tue, 21 May 2024 14:07:35 +0200 Subject: [PATCH] =?UTF-8?q?R=C3=A9agencement=20des=20tables=20et=20de=20le?= =?UTF-8?q?urs=20attributs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/food/migrations/0001_initial.py | 110 +++++++++--------- .../migrations/0002_auto_20240521_1103.py | 19 --- .../migrations/0003_auto_20240521_1110.py | 19 --- apps/food/models.py | 84 +++++++------ 4 files changed, 101 insertions(+), 131 deletions(-) delete mode 100644 apps/food/migrations/0002_auto_20240521_1103.py delete mode 100644 apps/food/migrations/0003_auto_20240521_1110.py diff --git a/apps/food/migrations/0001_initial.py b/apps/food/migrations/0001_initial.py index 46899dd6..49b7a329 100644 --- a/apps/food/migrations/0001_initial.py +++ b/apps/food/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.28 on 2024-05-17 18:44 +# Generated by Django 2.2.28 on 2024-05-21 12:05 from django.db import migrations, models import django.db.models.deletion @@ -14,6 +14,58 @@ class Migration(migrations.Migration): ] operations = [ + migrations.CreateModel( + name='Basic_food', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255, verbose_name='name')), + ('is_DLC', models.BooleanField(default=False, verbose_name='is DLC')), + ('is_DDM', models.BooleanField(default=False, verbose_name='is DDM')), + ('expiry_date', models.DateTimeField(blank=True, default=django.utils.timezone.now, verbose_name='expiry date')), + ('label', models.ImageField(default='pic/default.png', max_length=255, upload_to='label/', verbose_name='food label')), + ('was_eaten', models.BooleanField(default=False, verbose_name='was eaten')), + ('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='member.Club', verbose_name='owner')), + ], + options={ + 'verbose_name': 'Basic food', + 'verbose_name_plural': 'Basic foods', + }, + ), + migrations.CreateModel( + name='Transformed_food', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255, verbose_name='name')), + ('creation_date', models.DateTimeField(verbose_name='creation date')), + ('expiry_date', models.DateTimeField(verbose_name='expiry date')), + ('is_active', models.BooleanField(default=True, verbose_name='is active')), + ('was_eaten', models.BooleanField(default=False, verbose_name='was eaten')), + ('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='member.Club', verbose_name='owner')), + ('transformed_ingredient', models.ManyToManyField(blank=True, related_name='transformed_ingredient_inv', to='food.Transformed_food', verbose_name='transformed ingredient')), + ], + options={ + 'verbose_name': 'Transformed food', + 'verbose_name_plural': 'Transformed foods', + }, + ), + migrations.CreateModel( + name='QR_code', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('qr_code_number', models.PositiveIntegerField(verbose_name='QR-code number')), + ('basic_food', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='QR_code', to='food.Basic_food', verbose_name='basic food')), + ('transformed_food_container', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='QR_code', to='food.Transformed_food', verbose_name='transformed food container')), + ], + options={ + 'verbose_name': 'QR-code', + 'verbose_name_plural': 'QR-codes', + }, + ), + migrations.AddField( + model_name='basic_food', + name='transformed_food', + field=models.ManyToManyField(blank=True, related_name='Basic_food', to='food.Transformed_food', verbose_name='transformed food'), + ), migrations.CreateModel( name='Allergen', fields=[ @@ -33,64 +85,12 @@ class Migration(migrations.Migration): ('groundnut', models.BooleanField(default=False, verbose_name='groundnut')), ('sesame', models.BooleanField(default=False, verbose_name='sesame')), ('alcohol', models.BooleanField(default=False, verbose_name='alcohol')), + ('basic_food', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='Allergen', to='food.Basic_food', verbose_name='basic food')), + ('transformed_food', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='Allergen', to='food.Transformed_food', verbose_name='transformed food')), ], options={ 'verbose_name': 'Allergen', 'verbose_name_plural': 'Allergens', }, ), - migrations.CreateModel( - name='Basic_food', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=255, verbose_name='name')), - ('is_DLC', models.BooleanField(default=False, verbose_name='is DLC')), - ('is_DDM', models.BooleanField(default=False, verbose_name='is DDM')), - ('expiry_date', models.DateTimeField(blank=True, default=django.utils.timezone.now, verbose_name='expiry date')), - ('label', models.ImageField(default='pic/default.png', max_length=255, upload_to='label/', verbose_name='food label')), - ('was_eaten', models.BooleanField(default=False, verbose_name='was eaten')), - ('allergen', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='food.Allergen', verbose_name='allergen')), - ('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='member.Club', verbose_name='owner')), - ], - options={ - 'verbose_name': 'Basic food', - 'verbose_name_plural': 'Basic foods', - }, - ), - migrations.CreateModel( - name='QR_code', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('qr_code_number', models.PositiveIntegerField(verbose_name='QR-code number')), - ], - options={ - 'verbose_name': 'QR-code', - 'verbose_name_plural': 'QR-codes', - }, - ), - migrations.CreateModel( - name='Transformed_food', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=255, verbose_name='name')), - ('creation_date', models.DateTimeField(verbose_name='creation date')), - ('expiry_date', models.DateTimeField(verbose_name='expiry date')), - ('is_active', models.BooleanField(default=True, verbose_name='is active')), - ('was_eaten', models.BooleanField(default=False, verbose_name='was eaten')), - ('allergen', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='food.Allergen', verbose_name='allergen')), - ('basic_ingredient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='food.Basic_food', verbose_name='basic ingredient')), - ('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='member.Club', verbose_name='owner')), - ('qr_code', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='food.QR_code', verbose_name='QR code')), - ('transformed_ingredient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='food.Transformed_food', verbose_name='transformed ingredient')), - ], - options={ - 'verbose_name': 'Transformed food', - 'verbose_name_plural': 'Transformed foods', - }, - ), - migrations.AddField( - model_name='basic_food', - name='qr_code', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='food.QR_code', verbose_name='QR code'), - ), ] diff --git a/apps/food/migrations/0002_auto_20240521_1103.py b/apps/food/migrations/0002_auto_20240521_1103.py deleted file mode 100644 index 6bdb8677..00000000 --- a/apps/food/migrations/0002_auto_20240521_1103.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.2.28 on 2024-05-21 09:03 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('food', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='transformed_food', - name='transformed_ingredient', - field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='food.Transformed_food', verbose_name='transformed ingredient'), - ), - ] diff --git a/apps/food/migrations/0003_auto_20240521_1110.py b/apps/food/migrations/0003_auto_20240521_1110.py deleted file mode 100644 index 9f92f534..00000000 --- a/apps/food/migrations/0003_auto_20240521_1110.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.2.28 on 2024-05-21 09:10 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('food', '0002_auto_20240521_1103'), - ] - - operations = [ - migrations.AlterField( - model_name='transformed_food', - name='transformed_ingredient', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='food.Transformed_food', verbose_name='transformed ingredient'), - ), - ] diff --git a/apps/food/models.py b/apps/food/models.py index 5347abc5..7deeb902 100644 --- a/apps/food/models.py +++ b/apps/food/models.py @@ -19,7 +19,25 @@ class QR_code(models.Model): An QR_code model """ qr_code_number = models.PositiveIntegerField( - verbose_name=_("QR-code number"), + verbose_name=_("QR-code number"), + ) + + transformed_food_container = models.ForeignKey( + 'Transformed_food', + on_delete = models.PROTECT, + related_name = 'QR_code', + null = True, + blank = True, + verbose_name = _('transformed food container'), + ) + + basic_food = models.ForeignKey( + 'Basic_food', + on_delete = models.PROTECT, + related_name = 'QR_code', + null = True, + blank = True, + verbose_name = _('basic food'), ) class Meta: @@ -109,6 +127,24 @@ class Allergen(models.Model): verbose_name = _('alcohol'), ) + transformed_food = models.ForeignKey( + 'Transformed_food', + on_delete = models.CASCADE, + related_name = 'Allergen', + blank = True, + null = True, + verbose_name = _('transformed food'), + ) + + basic_food = models.ForeignKey( + 'Basic_food', + on_delete = models.CASCADE, + related_name = 'Allergen', + blank = True, + null = True, + verbose_name = _('basic food'), + ) + class Meta: verbose_name = _('Allergen') verbose_name_plural = _('Allergens') @@ -158,25 +194,19 @@ class Basic_food(models.Model): default= 'pic/default.png', ) - qr_code = models.ForeignKey( - QR_code, - on_delete=models.PROTECT, - related_name= '+', - verbose_name=_('QR code'), - ) - was_eaten = models.BooleanField( verbose_name=_('was eaten'), default = False, ) - allergen = models.ForeignKey( - Allergen, - on_delete = models.PROTECT, - related_name = '+', - verbose_name = _('allergen'), + transformed_food = models.ManyToManyField( + 'Transformed_food', + related_name= 'Basic_food', + blank = True, + verbose_name = _('transformed food'), ) + class Meta: verbose_name=_('Basic food') verbose_name_plural=_('Basic foods') @@ -208,46 +238,24 @@ class Transformed_food(models.Model): verbose_name =_('owner'), ) - transformed_ingredient = models.ForeignKey( + transformed_ingredient = models.ManyToManyField( "self", - on_delete = models.CASCADE, blank = True, - null = True, - related_name = '+', + symmetrical = False, + related_name = 'transformed_ingredient_inv', verbose_name = _('transformed ingredient'), ) - basic_ingredient = models.ForeignKey( - Basic_food, - on_delete = models.CASCADE, - related_name = '+', - verbose_name = _('basic ingredient'), - ) - - is_active = models.BooleanField( default = True, verbose_name = _('is active'), ) - qr_code = models.ForeignKey( - QR_code, - on_delete = models.CASCADE, - related_name = '+', - verbose_name = _('QR code'), - ) - was_eaten = models.BooleanField( default = False, verbose_name = _('was eaten'), ) - allergen = models.ForeignKey( - Allergen, - on_delete = models.PROTECT, - related_name= '+', - verbose_name = _('allergen'), - ) class Meta: verbose_name = _('Transformed food')