From 74e3d0906535b68dbfbbbde0aaf577c81b92797e Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Thu, 17 Jun 2021 15:23:39 +0200 Subject: [PATCH] moved to new migration --- .../migrations/0135_auto_20210615_2210.py | 23 ++----------------- .../migrations/0137_auto_20210617_1501.py | 21 ++++++++++++++++- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cookbook/migrations/0135_auto_20210615_2210.py b/cookbook/migrations/0135_auto_20210615_2210.py index 49517f031..0b9c0a3b6 100644 --- a/cookbook/migrations/0135_auto_20210615_2210.py +++ b/cookbook/migrations/0135_auto_20210615_2210.py @@ -1,26 +1,7 @@ # Generated by Django 3.2.4 on 2021-06-15 20:10 -from django.db import migrations -from django.db.models import Subquery, OuterRef -from django_scopes import scopes_disabled -from django.db import migrations, models import django.db.models.deletion - - -def migrate_spaces(apps, schema_editor): - with scopes_disabled(): - Recipe = apps.get_model('cookbook', 'Recipe') - Step = apps.get_model('cookbook', 'Step') - Ingredient = apps.get_model('cookbook', 'Ingredient') - NutritionInformation = apps.get_model('cookbook', 'NutritionInformation') - - Step.objects.filter(recipe__isnull=True).delete() - Ingredient.objects.filter(step__recipe__isnull=True).delete() - NutritionInformation.objects.filter(recipe__isnull=True).delete() - - Step.objects.update(space=Subquery(Step.objects.filter(pk=OuterRef('pk')).values('recipe__space')[:1])) - Ingredient.objects.update(space=Subquery(Ingredient.objects.filter(pk=OuterRef('pk')).values('step__recipe__space')[:1])) - NutritionInformation.objects.update(space=Subquery(NutritionInformation.objects.filter(pk=OuterRef('pk')).values('recipe__space')[:1])) +from django.db import migrations, models class Migration(migrations.Migration): @@ -44,5 +25,5 @@ class Migration(migrations.Migration): name='space', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='cookbook.space'), ), - migrations.RunPython(migrate_spaces), + ] diff --git a/cookbook/migrations/0137_auto_20210617_1501.py b/cookbook/migrations/0137_auto_20210617_1501.py index b4e9a397a..4fe1ca3aa 100644 --- a/cookbook/migrations/0137_auto_20210617_1501.py +++ b/cookbook/migrations/0137_auto_20210617_1501.py @@ -1,16 +1,35 @@ # Generated by Django 3.2.4 on 2021-06-17 13:01 +from django.db import migrations +from django.db.models import Subquery, OuterRef +from django_scopes import scopes_disabled from django.db import migrations, models import django.db.models.deletion -class Migration(migrations.Migration): +def migrate_spaces(apps, schema_editor): + with scopes_disabled(): + Recipe = apps.get_model('cookbook', 'Recipe') + Step = apps.get_model('cookbook', 'Step') + Ingredient = apps.get_model('cookbook', 'Ingredient') + NutritionInformation = apps.get_model('cookbook', 'NutritionInformation') + Step.objects.filter(recipe__isnull=True).delete() + Ingredient.objects.filter(step__recipe__isnull=True).delete() + NutritionInformation.objects.filter(recipe__isnull=True).delete() + + Step.objects.update(space=Subquery(Step.objects.filter(pk=OuterRef('pk')).values('recipe__space')[:1])) + Ingredient.objects.update(space=Subquery(Ingredient.objects.filter(pk=OuterRef('pk')).values('step__recipe__space')[:1])) + NutritionInformation.objects.update(space=Subquery(NutritionInformation.objects.filter(pk=OuterRef('pk')).values('recipe__space')[:1])) + + +class Migration(migrations.Migration): dependencies = [ ('cookbook', '0136_auto_20210617_1343'), ] operations = [ + migrations.RunPython(migrate_spaces), migrations.AlterField( model_name='ingredient', name='space',