created TreeTag model, fixes for addtaxonomy command
This commit is contained in:
@@ -3,6 +3,8 @@ import logging
|
|||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
from core.models import TreeTag
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
|
||||||
@@ -11,16 +13,20 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **kwargs):
|
def handle(self, *args, **kwargs):
|
||||||
|
|
||||||
print(self.help)
|
print(self.help)
|
||||||
|
print("Deleting existing instances")
|
||||||
|
TreeTag.objects.all().delete()
|
||||||
|
|
||||||
file_path = settings.BASE_DIR + '/../datasets/' + settings.TAXONOMY_FILE
|
file_path = settings.BASE_DIR + '/../datasets/' + settings.TAXONOMY_FILE
|
||||||
counter = 0
|
counter = 0
|
||||||
with open(file_path, 'rt') as data_file:
|
with open(file_path, 'rt') as data_file:
|
||||||
print(f"Reading from {settings.TAXONOMY_FILE}")
|
print(f"Reading from {settings.TAXONOMY_FILE}")
|
||||||
for line in data_file.readlines():
|
for line in data_file.readlines():
|
||||||
try:
|
try:
|
||||||
tag = TagModel.objects.create(name=line)
|
tag = TreeTag.objects.create(name=line)
|
||||||
counter += 1
|
counter += 1
|
||||||
|
print('.', end='')
|
||||||
logging.debug(f"{tag} created from {line}")
|
logging.debug(f"{tag} created from {line}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"{type(e)} while creating tags from {settings.TAXONOMY_FILE}")
|
logging.error(f"{type(e)} while creating tags from {settings.TAXONOMY_FILE}")
|
||||||
print(f"{counter} new TagModel instances created")
|
print(f"\n{counter} new TreeTag instances created")
|
||||||
print('Shutting down\n')
|
print('Shutting down\n')
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **kwargs):
|
def handle(self, *args, **kwargs):
|
||||||
print("Creating fake data to populate database")
|
print("Creating fake data to populate database")
|
||||||
|
|
||||||
|
|
||||||
# start faker
|
# start faker
|
||||||
fake = Faker()
|
fake = Faker()
|
||||||
Faker.seed(0)
|
Faker.seed(0)
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ from django.db import models
|
|||||||
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
|
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
|
||||||
from django.contrib.auth.models import PermissionsMixin
|
from django.contrib.auth.models import PermissionsMixin
|
||||||
|
|
||||||
|
from tagulous.models import TagTreeModel
|
||||||
|
|
||||||
from companies.models import Company
|
from companies.models import Company
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
@@ -71,3 +73,9 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
|
|||||||
verbose_name = 'Usuario'
|
verbose_name = 'Usuario'
|
||||||
verbose_name_plural = 'Usuarios'
|
verbose_name_plural = 'Usuarios'
|
||||||
|
|
||||||
|
|
||||||
|
class TreeTag(TagTreeModel):
|
||||||
|
class TagMeta:
|
||||||
|
# initial = "food/eating, food/cooking, gaming/football"
|
||||||
|
force_lowercase = True
|
||||||
|
# autocomplete_view = 'myapp.views.hobbies_autocomplete'
|
||||||
|
|||||||
Reference in New Issue
Block a user