From d2b310d0bdacf249882cd74fe0efa226d6550c21 Mon Sep 17 00:00:00 2001 From: through-your-tears Date: Sat, 6 Apr 2024 21:44:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=B0=D0=B3=20=D1=84=D0=B8=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/organizations/repositories.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/organizations/repositories.py b/src/organizations/repositories.py index e3d968f..6703f11 100644 --- a/src/organizations/repositories.py +++ b/src/organizations/repositories.py @@ -1,5 +1,5 @@ from .models import Category, Location, Organization, OrganizationImage, Region -from core.repositories import BaseRepository +from core.repositories import BaseRepository, ObjectDoesNotExist class CategoryRepository(BaseRepository): @@ -16,10 +16,12 @@ class LocationRepository(BaseRepository): @classmethod def get_or_create(cls, coords, address, region=None): if region is None: - region = 23 - if Location.objects.get(coords=coords): - return Location.objects.get(coords=coords) + region = Region.objects.get_or_create(code=23) else: + region = Region.objects.get(code=region) + try: + return Location.objects.get(coords=coords) + except ObjectDoesNotExist: obj = LocationRepository.create( coords=coords, region=region,