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')

View File

@@ -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():

View File

@@ -73,10 +73,3 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
verbose_name = 'Usuario'
verbose_name_plural = 'Usuarios'
class TreeTag(TagTreeModel):
class TagMeta:
initial = ""
force_lowercase = True
max_count=20
# autocomplete_view = 'myapp.views.hobbies_autocomplete'