changes to readme, and addtaxonomy

This commit is contained in:
Sam
2021-02-12 12:34:08 +00:00
parent e5fdeb7cdb
commit bd8d05bd39
2 changed files with 19 additions and 9 deletions

View File

@@ -5,9 +5,10 @@ This README aims to document functionality of backend as well as required steps
## Table of Contents ## Table of Contents
- [First Steps](#first-steps) - [First Steps](#first-steps)
- [Location Data](#location-data) - [Load location data](#load-location-data)
- [Load taxonomy data](#load-taxonomy-data)
- [Endpoints](#endpoints) - [Endpoints](#endpoints)
- [Data Load](#data-load) - [Massive Data Load Endpoints](#massive-data-load-endpoints)
- [GeoIP Setup](#geoip-setup) - [GeoIP Setup](#geoip-setup)
- [Development Utils](#development-utils) - [Development Utils](#development-utils)
@@ -35,13 +36,20 @@ python manage.py migrate
- Start server in development mode: `python manage.py runserver` - Start server in development mode: `python manage.py runserver`
## Location data
### Load Location Data
To load initial location data use: `python manage.py loadgisdata` To load initial location data use: `python manage.py loadgisdata`
## Endpoints ### Load Taxonomy Data
This data serves as initial Tags
To load initial set of tags: `python manage.py addtaxonomy`
## Endpoints
### User Management ### User Management
@@ -146,7 +154,7 @@ Endpoint url: `/api/v1/stats/`
logs about user interaction with products links logs about user interaction with products links
### Geo location ## Geo location
Location ednpoints: Location ednpoints:
@@ -156,7 +164,7 @@ Location ednpoints:
- `/api/v1/cities/` - `/api/v1/cities/`
## Load Data ## Massive Data Data Endpoints
### COOP and Managing User Data Load ### COOP and Managing User Data Load

View File

@@ -4,11 +4,12 @@ from django.core.management.base import BaseCommand
from django.conf import settings from django.conf import settings
from core.models import TreeTag from core.models import TreeTag
from products.models import Product
class Command(BaseCommand): class Command(BaseCommand):
help = 'Load taxonomy terms into Tags' help = 'Load taxonomy terms into Product.tags'
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
@@ -22,11 +23,12 @@ class Command(BaseCommand):
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 = TreeTag.objects.create(name=line) # tag = TreeTag.objects.create(name=line)
tag = Product.tags.tag_model.objects.create(name=line)
counter += 1 counter += 1
print('.', end='') 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"\n{counter} new TreeTag instances created") print(f"\nAdded {counter} Tag objects to Product.tags")
print('Shutting down\n') print('Shutting down\n')