mybuddy/babybuddy/migrations/0002_add_settings.py

25 lines
615 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from django.db import migrations
def add_settings(apps, schema_editor):
2022-02-10 00:00:30 +00:00
Settings = apps.get_model("babybuddy", "Settings")
User = apps.get_model("auth", "User")
for user in User.objects.all():
if Settings.objects.filter(user=user).count() == 0:
settings = Settings.objects.create(user=user)
settings.save()
class Migration(migrations.Migration):
initial = True
dependencies = [
2022-02-10 00:00:30 +00:00
("babybuddy", "0001_initial"),
]
operations = [
migrations.RunPython(add_settings, reverse_code=migrations.RunPython.noop),
]