Merge branch 'develop' into feature/est_transporation

This commit is contained in:
GladkihViktor 2019-11-02 17:55:08 +03:00
commit 4d310515ab

View File

@ -10,7 +10,9 @@ class Command(BaseCommand):
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
existing_establishment = Establishment.objects.filter(old_id__isnull=False) existing_establishment = Establishment.objects.filter(
old_id__isnull=False
)
ESTABLISHMENT = 1 ESTABLISHMENT = 1
SHOP = 2 SHOP = 2
RESTAURANT = 3 RESTAURANT = 3
@ -52,7 +54,9 @@ class Command(BaseCommand):
# create Tag # create Tag
for tag in key_value.metadata_set.filter( for tag in key_value.metadata_set.filter(
establishment__id__in=list(existing_establishment.values_list('old_id', flat=True))): establishment__id__in=list(
existing_establishment.values_list('old_id', flat=True)
)):
new_tag, _ = Tag.objects.get_or_create( new_tag, _ = Tag.objects.get_or_create(
label={ label={
@ -63,7 +67,8 @@ class Command(BaseCommand):
value=tag.value, value=tag.value,
category=tag_category, category=tag_category,
) )
est = existing_establishment.get(old_id=tag.establishment_id) est = existing_establishment.filter(
est.tags.add(new_tag) old_id=tag.establishment_id, tags__isnull=True).first()
est.save() if est:
est.tags.add(new_tag)
est.save()