individual models for each tagged field in Product

This commit is contained in:
Sam
2021-02-25 11:17:35 +00:00
parent 8ea0f74b8c
commit db55de0cf5
6 changed files with 41 additions and 24 deletions

View File

@@ -3,7 +3,7 @@ import logging
from django.core.management.base import BaseCommand
from django.conf import settings
from core.models import TreeTag
from products.models import CategoryTag
from products.models import Product
@@ -15,7 +15,7 @@ class Command(BaseCommand):
print(self.help)
print("Deleting existing instances")
TreeTag.objects.all().delete()
CategoryTag.objects.all().delete()
file_path = settings.BASE_DIR + '/../datasets/' + settings.TAXONOMY_FILE
counter = 0
@@ -23,11 +23,11 @@ class Command(BaseCommand):
print(f"Reading from {settings.TAXONOMY_FILE}")
for line in data_file.readlines():
try:
tag = Product.tags.tag_model.objects.create(name=line)
tag = Product.category.tag_model.objects.create(name=line)
counter += 1
print('.', end='')
logging.debug(f"{tag} created from {line}")
except Exception as e:
logging.error(f"{type(e)} while creating tags from {settings.TAXONOMY_FILE}")
print(f"\nAdded {counter} Tag objects to Product.tags")
print(f"\nAdded {counter} Tag objects to Product.category")
print('Shutting down\n')