# Generated by Django 3.1.7 on 2021-03-28 13:49

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


def forwards_func(apps, schema_editor):
    Brewery = apps.get_model("breweries", "Brewery")
    db_alias = schema_editor.connection.alias

    for b in Brewery.objects.using(db_alias).all():
        if b.latitude is not None and b.longitude is not None:
            b.point = Point(x=b.longitude, y=b.latitude, srid=4326)
            b.save()


def reverse_func(apps, schema_editor):
    Brewery = apps.get_model("breweries", "Brewery")
    db_alias = schema_editor.connection.alias
    Brewery.objects.using(db_alias).all().update(point=None)


class Migration(migrations.Migration):

    dependencies = [
        ('breweries', '0002_auto_20210327_2344'),
    ]

    operations = [
        migrations.RunPython(forwards_func, reverse_func),
    ]
