<reponame>alaasalman/moneytracker
# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2018-01-15 01:52
from __future__ import unicode_literals

from django.db import migrations


def createdefaultuserprofile(apps, schema_editor):
    """
    Create default profile for existing users
    """
    UserModel = apps.get_model('walletweb', 'WalletyUser')
    UserProfileModel = apps.get_model('walletweb', 'UserProfile')
    CurrencyModel = apps.get_model('walletweb', 'Currency')

    users = UserModel.objects.all()
    default_currency = CurrencyModel.objects.first() # first currency is fine for default

    for user in users:
        if not hasattr(user, 'userprofile'):
            profile = UserProfileModel(user=user, display_currency=default_currency)
            profile.save()
            user.profile = profile
            user.save()


def reverse(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('walletweb', '0015_fillintransactioncurrencyifempty'),
    ]

    operations = [
        migrations.RunPython(createdefaultuserprofile, reverse),
    ]

# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2018-01-15 01:52
from __future__ import unicode_literals

from django.db import migrations


def createdefaultuserprofile(apps, schema_editor):
    """
    Create default profile for existing users
    """
    UserModel = apps.get_model('walletweb', 'WalletyUser')
    UserProfileModel = apps.get_model('walletweb', 'UserProfile')
    CurrencyModel = apps.get_model('walletweb', 'Currency')

    users = UserModel.objects.all()
    default_currency = CurrencyModel.objects.first() # first currency is fine for default

    for user in users:
        if not hasattr(user, 'userprofile'):
            profile = UserProfileModel(user=user, display_currency=default_currency)
            profile.save()
            user.profile = profile
            user.save()


def reverse(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('walletweb', '0015_fillintransactioncurrencyifempty'),
    ]

    operations = [
        migrations.RunPython(createdefaultuserprofile, reverse),
    ]
# -*- coding: utf-8 -*- # Generated by Django 1.10.8 on 2018-01-15 01:52 Create default profile for existing users # first currency is fine for default