# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2017-09-14 11:01
from __future__ import unicode_literals

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

import os


def load_data_currency(apps, schema_editor):
    currency_model = apps.get_model('bank', 'Currency')
    with open(os.path.join(settings.BASE_DIR, 'bank', 'fixtures', 'currency.json'), 'rb') as data:
        currencies = serializers.deserialize('json', data)
        currency_model.objects.bulk_create((currency.object for currency in currencies))


def unload_data_currency(apps, schema_editor):
    apps.get_model('core', 'CountryNumberphone').objects.all().delete()


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Currency',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=50)),
                ('short_name', models.CharField(max_length=3)),
            ],
        ),
        migrations.CreateModel(
            name='ExchangeRate',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('rate', models.FloatField()),
                ('created', models.DateTimeField()),
                ('currency', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bank.Currency')),
            ],

        ),
        migrations.RunPython(
            load_data_currency,
            reverse_code=unload_data_currency
        ),

    ]
