filter for tag

This commit is contained in:
Dmitriy Kuzmenko 2019-11-02 17:19:59 +03:00
parent f3f06fcf09
commit 7de6043861

View File

@ -12,8 +12,6 @@ class Command(BaseCommand):
existing_establishment = Establishment.objects.filter( existing_establishment = Establishment.objects.filter(
old_id__isnull=False old_id__isnull=False
).filter(
tags__isnull=True
) )
ESTABLISHMENT = 1 ESTABLISHMENT = 1
SHOP = 2 SHOP = 2
@ -56,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={
@ -67,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(
old_id=tag.establishment_id, tags__isnull=True).first()
if est:
est.tags.add(new_tag) est.tags.add(new_tag)
est.save() est.save()