From e82334baf2c14faf489a816b6c0f7de35a3a25f0 Mon Sep 17 00:00:00 2001 From: George Silva Date: Thu, 26 Jan 2017 18:14:53 -0200 Subject: [PATCH 1/2] advancing on the boundary implementation --- README.md | 19 +++++++- cities/migrations/0011_auto_20170126_1717.py | 51 ++++++++++++++++++++ cities/models.py | 10 ++++ test_project/test_app/settings.py | 4 +- 4 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 cities/migrations/0011_auto_20170126_1717.py diff --git a/README.md b/README.md index 975c1de5..4d5d891d 100644 --- a/README.md +++ b/README.md @@ -527,8 +527,6 @@ Data will only be downloaded/imported if it is newer than your data, and only ma The cities manage command has options, see `--help`. Verbosity is controlled through the `LOGGING` setting. - - ## Running Tests 1. Install postgres, postgis and libgdal-dev @@ -549,6 +547,23 @@ The cities manage command has options, see `--help`. Verbosity is controlled th # changes to github and specify commit and repo variables: TRAVIS_COMMIT=`git rev-parse HEAD` TRAVIS_REPO_SLUG='github-username/django-cities' POSTGRES_USER=some_username POSTGRES_PASSWORD='password from createuser ste' tox +## Running Django command + +If you need to run django comamnds, like ```makemigrations``` or ```makemessages``` (I guess the next step is +to make the software more compatible with other languages), you can do so easily, by configuring a few environment +variables **before** the actual command, like so: + +```bash +cd django-cities/ +POSTGRES_USER= POSTGRES_PASSWORD= PYTHONPATH=. python test_project/manage.py makemigrations cities +``` + +A few things should be noted: + +1. The ```cd``` command should point at the repository root; +1. The `````` and `````` are placeholders. That mean that you should substitute +them for the actual values of your database. + #### Useful test options: * `TRAVIS_LOG_LEVEL` - defaults to `INFO`, but set to `DEBUG` to see a (very) large and (very) complete log of the import script diff --git a/cities/migrations/0011_auto_20170126_1717.py b/cities/migrations/0011_auto_20170126_1717.py new file mode 100644 index 00000000..ad431fa6 --- /dev/null +++ b/cities/migrations/0011_auto_20170126_1717.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-01-26 17:17 +from __future__ import unicode_literals + +import django.contrib.gis.db.models.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('cities', '0010_adjust_unique_attributes'), + ] + + operations = [ + migrations.AddField( + model_name='city', + name='boundary', + field=django.contrib.gis.db.models.fields.MultiPolygonField(null=True, srid=4326), + ), + migrations.AddField( + model_name='continent', + name='boundary', + field=django.contrib.gis.db.models.fields.MultiPolygonField(null=True, srid=4326), + ), + migrations.AddField( + model_name='country', + name='boundary', + field=django.contrib.gis.db.models.fields.MultiPolygonField(null=True, srid=4326), + ), + migrations.AddField( + model_name='district', + name='boundary', + field=django.contrib.gis.db.models.fields.MultiPolygonField(null=True, srid=4326), + ), + migrations.AddField( + model_name='postalcode', + name='boundary', + field=django.contrib.gis.db.models.fields.MultiPolygonField(null=True, srid=4326), + ), + migrations.AddField( + model_name='region', + name='boundary', + field=django.contrib.gis.db.models.fields.MultiPolygonField(null=True, srid=4326), + ), + migrations.AddField( + model_name='subregion', + name='boundary', + field=django.contrib.gis.db.models.fields.MultiPolygonField(null=True, srid=4326), + ), + ] diff --git a/cities/models.py b/cities/models.py index 4d3c4fde..74cd7660 100644 --- a/cities/models.py +++ b/cities/models.py @@ -59,6 +59,8 @@ class Place(models.Model): name = models.CharField(max_length=200, db_index=True, verbose_name="ascii name") alt_names = models.ManyToManyField('AlternativeName') + boundary = models.MultiPolygonField(null=True) + objects = models.GeoManager() class Meta: @@ -86,6 +88,8 @@ def save(self, *args, **kwargs): class BaseContinent(Place, SlugModel): code = models.CharField(max_length=2, unique=True, db_index=True) + objects = models.GeoManager() + def __str__(self): return force_text(self.name) @@ -119,6 +123,8 @@ class BaseCountry(Place, SlugModel): capital = models.CharField(max_length=100) neighbours = models.ManyToManyField("self") + objects = models.GeoManager() + class Meta: abstract = True ordering = ['name'] @@ -149,6 +155,8 @@ class Region(Place, SlugModel): country = models.ForeignKey(swapper.get_model_name('cities', 'Country'), related_name='regions') + objects = models.GeoManager() + class Meta: unique_together = (('country', 'name'),) @@ -202,6 +210,8 @@ class BaseCity(Place, SlugModel): kind = models.CharField(max_length=10) # http://www.geonames.org/export/codes.html timezone = models.CharField(max_length=40) + objects = models.GeoManager() + class Meta: abstract = True unique_together = (('country', 'region', 'subregion', 'id', 'name'),) diff --git a/test_project/test_app/settings.py b/test_project/test_app/settings.py index 0e926274..552a06a6 100644 --- a/test_project/test_app/settings.py +++ b/test_project/test_app/settings.py @@ -52,9 +52,9 @@ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) -ROOT_URLCONF = 'test_project.urls' +ROOT_URLCONF = 'test_app.urls' -WSGI_APPLICATION = 'test_project.wsgi.application' +WSGI_APPLICATION = 'test_app.wsgi.application' # Database From 012270e0fe526485803d7a479319505e89a00c03 Mon Sep 17 00:00:00 2001 From: George Silva Date: Fri, 27 Jan 2017 09:06:20 -0200 Subject: [PATCH 2/2] removing extra manager declaration --- cities/models.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cities/models.py b/cities/models.py index 74cd7660..ed23f5bf 100644 --- a/cities/models.py +++ b/cities/models.py @@ -123,8 +123,6 @@ class BaseCountry(Place, SlugModel): capital = models.CharField(max_length=100) neighbours = models.ManyToManyField("self") - objects = models.GeoManager() - class Meta: abstract = True ordering = ['name'] @@ -155,8 +153,6 @@ class Region(Place, SlugModel): country = models.ForeignKey(swapper.get_model_name('cities', 'Country'), related_name='regions') - objects = models.GeoManager() - class Meta: unique_together = (('country', 'name'),) @@ -210,8 +206,6 @@ class BaseCity(Place, SlugModel): kind = models.CharField(max_length=10) # http://www.geonames.org/export/codes.html timezone = models.CharField(max_length=40) - objects = models.GeoManager() - class Meta: abstract = True unique_together = (('country', 'region', 'subregion', 'id', 'name'),) @@ -268,8 +262,6 @@ class AlternativeName(SlugModel): is_colloquial = models.BooleanField(default=False) is_historic = models.BooleanField(default=False) - objects = AlternativeNameManager() - def __str__(self): return "%s (%s)" % (force_text(self.name), force_text(self.language_code)) @@ -300,8 +292,6 @@ class PostalCode(Place, SlugModel): blank=True, null=True, related_name='postal_codes') district = models.ForeignKey(District, blank=True, null=True, related_name='postal_codes') - objects = models.GeoManager() - class Meta: unique_together = ( ('country', 'region', 'subregion', 'city', 'district', 'name', 'id', 'code'),