# Generated by Django 2.2.1 on 2019-05-09 18:26
import itertools

from django.contrib.gis.geos import Point
from django.db import migrations


def migrate_long_lat_to_geo_point(apps, schema_editor):
    # May run for quite a long time
    RentApartment = apps.get_model('apartments_analyzer', 'RentApartment')
    SoldApartments = apps.get_model('apartments_analyzer', 'SoldApartments')
    for apartment in itertools.chain(
            RentApartment.objects.values("latitude", "longitude"), SoldApartments.objects.values("latitude", "longitude")
    ):
        apartment.location = Point(
            x=float(apartment.longitude),
            y=float(apartment.latitude),
            srid=4326)
        apartment.save(update_fields=("location", ))


class Migration(migrations.Migration):

    dependencies = [
        ('apartments_analyzer', '0016_auto_20190509_2126'),
    ]

    operations = [
        migrations.RunPython(migrate_long_lat_to_geo_point),
    ]
