Skip to content

Commit

Permalink
Update cities.py
Browse files Browse the repository at this point in the history
Added workaround from here:
coderholic#180 (comment)
  • Loading branch information
sowinski authored Oct 15, 2018
1 parent 1a60b31 commit 26f7833
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cities/management/commands/cities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,19 @@ def import_postal_code(self):
region__country=pc.country)
except Subregion.DoesNotExist:
pc.subregion = None
except Subregion.MultipleObjectsReturned:
self.logger.warn("Found multiple subregions for '{}' in '{}' - ignoring".format(
pc.region_name,
pc.subregion_name))
self.logger.debug("item: {}\nsubregions: {}".format(
item,
Subregion.objects.filter(
Q(region__name_std__iexact=pc.region_name) |
Q(region__name__iexact=pc.region_name),
Q(name_std__iexact=pc.subregion_name) |
Q(name__iexact=pc.subregion_name),
region__country=pc.country).values_list('id', flat=True)))
pc.subregion = None
else:
pc.subregion = None

Expand Down

0 comments on commit 26f7833

Please sign in to comment.