work on initial tag load
This commit is contained in:
26
core/management/commands/addtaxonomy.py
Normal file
26
core/management/commands/addtaxonomy.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import logging
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
help = 'Load taxonomy terms into Tags'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
|
||||
print(self.help)
|
||||
file_path = settings.BASE_DIR + '/../datasets/' + settings.TAXONOMY_FILE
|
||||
counter = 0
|
||||
with open(file_path, 'rt') as data_file:
|
||||
print(f"Reading from {settings.TAXONOMY_FILE}")
|
||||
for line in data_file.readlines():
|
||||
try:
|
||||
tag = TagModel.objects.create(name=line)
|
||||
counter += 1
|
||||
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"{counter} new TagModel instances created")
|
||||
print('Shutting down\n')
|
||||
Reference in New Issue
Block a user