better migration for unit fix

This commit is contained in:
vabene1111 2020-12-27 23:10:22 +01:00
parent 5a9270373f
commit 1775b64ba4

View File

@ -5,15 +5,14 @@ from django.db import migrations
def migrate_empty_units(apps, schema_editor):
Unit = apps.get_model('cookbook', 'Unit')
Step = apps.get_model('cookbook', 'Step')
Ingredient = apps.get_model('cookbook', 'Ingredient')
empty_units = Unit.objects.filter(name='').all()
for x in empty_units:
for s in Step.objects.all():
for i in s.ingredients.all():
if i.unit == x:
i.unit = None
i.save()
for i in Ingredient.objects.all():
if i.unit == x:
i.unit = None
i.save()
x.delete()