mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 04:10:06 -05:00
fixed empty units/foods (again)
This commit is contained in:
40
cookbook/migrations/0116_auto_20210319_0012.py
Normal file
40
cookbook/migrations/0116_auto_20210319_0012.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# Generated by Django 3.1.7 on 2021-03-18 23:12
|
||||
|
||||
from django.db import migrations
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
def remove_empty_food_unit(apps, schema_editor):
|
||||
with scopes_disabled():
|
||||
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
||||
ShoppingListEntry = apps.get_model('cookbook', 'ShoppingListEntry')
|
||||
|
||||
Food = apps.get_model('cookbook', 'Food')
|
||||
Unit = apps.get_model('cookbook', 'Unit')
|
||||
|
||||
for f in Food.objects.filter(name='').all():
|
||||
for o in Ingredient.objects.filter(food=f):
|
||||
o.food = None
|
||||
o.save()
|
||||
|
||||
for o in ShoppingListEntry.objects.filter(food=f):
|
||||
o.delete()
|
||||
|
||||
for u in Unit.objects.filter(name='').all():
|
||||
for o in Ingredient.objects.filter(unit=u):
|
||||
o.unit = None
|
||||
o.save()
|
||||
|
||||
for o in ShoppingListEntry.objects.filter(unit=u):
|
||||
o.unit = None
|
||||
o.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('cookbook', '0115_telegrambot'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(remove_empty_food_unit),
|
||||
]
|
||||
Reference in New Issue
Block a user