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

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


def set_default_location(apps, schema_editor):
    # We can't import the Person model directly as it may be a newer
    # version than this migration expects. We use the historical version.
    Product = apps.get_model('catalog', 'Product')
    for product in Product.objects.all():
        product.location_id = settings.DEFAULT_LOCATION_ID
        product.save()


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0041_siteconfiguration_bottom_right_banner_icon'),
        ('catalog', '0019_auto_20170822_2108'),
    ]

    operations = [
        migrations.AddField(
            model_name='product',
            name='location',
            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='products', to='core.Location'),
        ),
        migrations.RunPython(set_default_location)
    ]
