Баг фикс

main
through-your-tears 9 months ago
parent 96972d4c3b
commit d2b310d0bd

@ -1,5 +1,5 @@
from .models import Category, Location, Organization, OrganizationImage, Region from .models import Category, Location, Organization, OrganizationImage, Region
from core.repositories import BaseRepository from core.repositories import BaseRepository, ObjectDoesNotExist
class CategoryRepository(BaseRepository): class CategoryRepository(BaseRepository):
@ -16,10 +16,12 @@ class LocationRepository(BaseRepository):
@classmethod @classmethod
def get_or_create(cls, coords, address, region=None): def get_or_create(cls, coords, address, region=None):
if region is None: if region is None:
region = 23 region = Region.objects.get_or_create(code=23)
if Location.objects.get(coords=coords):
return Location.objects.get(coords=coords)
else: else:
region = Region.objects.get(code=region)
try:
return Location.objects.get(coords=coords)
except ObjectDoesNotExist:
obj = LocationRepository.create( obj = LocationRepository.create(
coords=coords, coords=coords,
region=region, region=region,

Loading…
Cancel
Save