<commit_before># -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-05-02 18:48
from __future__ import unicode_literals

import django.contrib.gis.db.models.fields
from django.contrib.gis.geos import Point
from django.contrib.postgres.operations import CreateExtension
from django.db import migrations
from django.db.models import F


def populate_location(app_registry, schema_editor):
    Place = app_registry.get_model('hosting', 'Place')
    places = Place._default_manager.filter(
        latitude__isnull=False,
        longitude__isnull=False,
    ).only('latitude', 'longitude')
    for place in places:
        print(place.longitude, place.latitude)
        place.location = Point(place.longitude, place.latitude)
        place.save()



class Migration(migrations.Migration):

    dependencies = [
        ('hosting', '0039_merge_20170613_1341'),
    ]

    operations = [
        # sudo -u postgres psql
        # postgres=# CREATE EXTENSION postgis;
        #
        # CreateExtension('postgis'),

        migrations.AddField(
            model_name='place',
            name='location',
            field=django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326, verbose_name='location'),
        ),
<commit_msg>assorted fixes: avoid creating empty (Geo)Points during migration<commit_after># -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-05-02 18:48
from __future__ import unicode_literals

import django.contrib.gis.db.models.fields
from django.contrib.gis.geos import Point
from django.contrib.postgres.operations import CreateExtension
from django.db import migrations
from django.db.models import F


def populate_location(app_registry, schema_editor):
    Place = app_registry.get_model('hosting', 'Place')
    places = Place._default_manager.filter(
        latitude__isnull=False,
        longitude__isnull=False,
    ).only('latitude', 'longitude').order_by('pk')
    for place in places:
        print(place.pk, place.longitude, place.latitude)
        place.location = Point(place.longitude, place.latitude)
        if not place.location.empty:
            place.save()



class Migration(migrations.Migration):

    dependencies = [
        ('hosting', '0039_merge_20170613_1341'),
    ]

    operations = [
        # sudo -u postgres psql
        # postgres=# CREATE EXTENSION postgis;
        #
        # CreateExtension('postgis'),

        migrations.AddField(
            model_name='place',
            name='location',
            field=django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326, verbose_name='location'),
        ),

{'fraction_non_alphanumeric': 0.11056231003039514, 'fraction_numerical': 0.02811550151975684, 'mean_word_length': 3.1529968454258674, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3308833', 'n_tokens_mistral': 849, 'n_tokens_neox': 781, 'n_words': 163}