# Generated by Django 3.2.13 on 2022-05-05 20:10

from products.ip2region import ip_to_region
from django.db import migrations, models

def populate_location(apps, schema_editor):
    ScanData = apps.get_model('products', 'ScanData')
    for sd in ScanData.objects.filter(location=None):
        if sd.ip:
            sd.location = ip_to_region(sd.ip)
            sd.save()

def nop(apps, schema_editor):
    pass

class Migration(migrations.Migration):

    dependencies = [
        ('products', '0040_alter_product_article'),
    ]

    operations = [
        migrations.AddField(
            model_name='scandata',
            name='location',
            field=models.CharField(max_length=128, null=True),
        ),
        migrations.RunPython(populate_location, nop),
    ]
