Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/cities_light/abstract_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class AbstractRegion(Base):
db_index=True)

country = models.ForeignKey(CITIES_LIGHT_APP_NAME + '.Country',
on_delete=models.CASCADE)
on_delete=models.CASCADE, to_field='geoname_id')

class Meta(Base.Meta):
unique_together = (('country', 'name'), ('country', 'slug'))
Expand All @@ -151,10 +151,10 @@ class AbstractSubRegion(Base):
db_index=True)

country = models.ForeignKey(CITIES_LIGHT_APP_NAME + '.Country',
on_delete=models.CASCADE)
on_delete=models.CASCADE, to_field='geoname_id')
region = models.ForeignKey(CITIES_LIGHT_APP_NAME + '.Region',
null=True, blank=True,
on_delete=models.CASCADE)
on_delete=models.CASCADE, to_field='geoname_id')

class Meta(Base.Meta):
verbose_name = _('SubRegion')
Expand Down Expand Up @@ -192,11 +192,11 @@ class AbstractCity(Base):

subregion = models.ForeignKey(CITIES_LIGHT_APP_NAME + '.SubRegion',
blank=True, null=True,
on_delete=models.CASCADE)
on_delete=models.CASCADE, to_field='geoname_id')
region = models.ForeignKey(CITIES_LIGHT_APP_NAME + '.Region', blank=True,
null=True, on_delete=models.CASCADE)
null=True, on_delete=models.CASCADE, to_field='geoname_id')
country = models.ForeignKey(CITIES_LIGHT_APP_NAME + '.Country',
on_delete=models.CASCADE)
on_delete=models.CASCADE, to_field='geoname_id')
population = models.BigIntegerField(null=True, blank=True, db_index=True)
feature_code = models.CharField(max_length=10, null=True, blank=True,
db_index=True)
Expand Down
8 changes: 4 additions & 4 deletions src/cities_light/management/commands/cities_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def _get_country_id(self, country_code2):
"""
if country_code2 not in self._country_codes:
self._country_codes[country_code2] = \
Country.objects.get(code2=country_code2).pk
Country.objects.get(code2=country_code2).geoname_id

return self._country_codes[country_code2]

Expand All @@ -284,7 +284,7 @@ def _get_region_id(self, country_code2, region_id):
country_id = self._get_country_id(country_code2)
if region_id not in self._region_codes[country_id]:
self._region_codes[country_id][region_id] = Region.objects.get(
country_id=country_id, geoname_code=region_id).pk
country_id=country_id, geoname_code=region_id).geoname_id

return self._region_codes[country_id][region_id]

Expand All @@ -296,13 +296,13 @@ def _get_subregion_id(self, country_code2, region_id, subregion_id):
country_id = self._get_country_id(country_code2)
if region_id not in self._region_codes[country_id]:
self._region_codes[country_id][region_id] = Region.objects.get(
country_id=country_id, geoname_code=region_id).pk
country_id=country_id, geoname_code=region_id).geoname_id

if subregion_id not in self._subregion_codes[country_id][region_id]:
self._subregion_codes[country_id][region_id][subregion_id] = \
SubRegion.objects.get(
region_id=self._region_codes[country_id][region_id],
geoname_code=subregion_id).pk
geoname_code=subregion_id).geoname_id
return self._subregion_codes[country_id][region_id][subregion_id]

def country_import(self, items):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Generated by Django 5.0.6 on 2024-06-09 22:26

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("cities_light", "0011_alter_city_country_alter_city_region_and_more"),
]

operations = [
migrations.AlterField(
model_name="city",
name="country",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="cities_light.country",
to_field="geoname_id",
),
),
migrations.AlterField(
model_name="city",
name="region",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="cities_light.region",
to_field="geoname_id",
),
),
migrations.AlterField(
model_name="city",
name="subregion",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="cities_light.subregion",
to_field="geoname_id",
),
),
migrations.AlterField(
model_name="region",
name="country",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="cities_light.country",
to_field="geoname_id",
),
),
migrations.AlterField(
model_name="subregion",
name="country",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="cities_light.country",
to_field="geoname_id",
),
),
migrations.AlterField(
model_name="subregion",
name="region",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="cities_light.region",
to_field="geoname_id",
),
),
]
Loading