mirror of https://github.com/snachodog/mybuddy.git
Add migration to handle existing users when adding the Settings model.
This commit is contained in:
parent
bd2655166e
commit
6ba5900928
|
@ -0,0 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def add_settings(apps, schema_editor):
|
||||
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 = [
|
||||
('babybuddy', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(add_settings, reverse_code=migrations.RunPython.noop),
|
||||
]
|
Loading…
Reference in New Issue