# Generated by Django 2.0.6 on 2018-07-04 12:32

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


def add_preference_to_user(apps, schema_editor):
    '''
    Make sure all users have preferences set up
    '''
    from django.contrib.auth.models import User
    UserPreference = apps.get_model('ivataraccount', 'UserPreference')
    for u in User.objects.filter(userpreference=None):
        p = UserPreference.objects.create(user_id=u.pk)
        p.save()


class Migration(migrations.Migration):

    dependencies = [
        ('auth', '0009_alter_user_last_name_max_length'),
        ('ivataraccount', '0007_auto_20180627_0624'),
    ]

    operations = [
        migrations.CreateModel(
            name='UserPreference',
            fields=[
                ('theme', models.CharField(choices=[('default', 'Default theme'), ('clime', 'Climes theme')], default='default', max_length=10)),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.RunPython(add_preference_to_user),
    ]
