individual models for each tagged field in Product
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -3,19 +3,19 @@ import logging
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
|
||||
from core.models import TreeTag
|
||||
from products.models import CategoryTag
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
help = 'Extract top level tags'
|
||||
help = 'Extract top level catefory tags'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
# get all instances
|
||||
tags = TreeTag.objects.all()
|
||||
tags = CategoryTag.objects.all()
|
||||
top_tags = []
|
||||
|
||||
print("Extracting top-level tags from TreeTag instances")
|
||||
print("Extracting top-level tags from CategoryTag instances")
|
||||
# extract tags with no ancestor
|
||||
for tag in tags:
|
||||
if not tag.get_ancestors():
|
||||
|
||||
Reference in New Issue
Block a user