changes to addtestdata
This commit is contained in:
@@ -9,7 +9,9 @@ from django.contrib.gis.geos import GEOSGeometry, MultiPolygon
|
|||||||
from faker import Faker
|
from faker import Faker
|
||||||
|
|
||||||
from companies.factories import CompanyFactory
|
from companies.factories import CompanyFactory
|
||||||
|
from companies.models import Company
|
||||||
from products.factories import ProductFactory
|
from products.factories import ProductFactory
|
||||||
|
from products.models import Product
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
@@ -25,7 +27,11 @@ class Command(BaseCommand):
|
|||||||
help = 'Creates fake companies and related products in database'
|
help = 'Creates fake companies and related products in database'
|
||||||
|
|
||||||
def handle(self, *args, **kwargs):
|
def handle(self, *args, **kwargs):
|
||||||
print("Creating fake data to populate database")
|
print("Create fake data to populate database\n")
|
||||||
|
|
||||||
|
print("Deleting existing Product and Company instances")
|
||||||
|
Product.objects.all().delete()
|
||||||
|
Company.objects.all().delete()
|
||||||
|
|
||||||
# start faker
|
# start faker
|
||||||
fake = Faker()
|
fake = Faker()
|
||||||
@@ -40,31 +46,34 @@ class Command(BaseCommand):
|
|||||||
company = CompanyFactory(company_name=name)
|
company = CompanyFactory(company_name=name)
|
||||||
new_companies.append(company)
|
new_companies.append(company)
|
||||||
logging.debug(f"New Company {company.company_name} created")
|
logging.debug(f"New Company {company.company_name} created")
|
||||||
print(".", end = '')
|
print(f"\t- {name}")
|
||||||
print('')
|
print('')
|
||||||
|
|
||||||
logging.info("Creating fake products")
|
logging.info("Creating fake products")
|
||||||
print("Creating fake products")
|
|
||||||
# create and assign products to companies
|
# create and assign products to companies
|
||||||
for company in new_companies:
|
for company in new_companies:
|
||||||
logging.info(f"Products for {company.company_name}")
|
print("Creating fake products for {company.company_name}")
|
||||||
|
logging.info(f"Creating Products for {company.company_name}")
|
||||||
for i in range(100):
|
for i in range(100):
|
||||||
name = fake.last_name_nonbinary()
|
name = fake.last_name_nonbinary()
|
||||||
description = fake.paragraph(nb_sentences=5)
|
description = fake.paragraph(nb_sentences=5)
|
||||||
# TODO: apply tags from tag list
|
# TODO: apply tags from tag list
|
||||||
|
|
||||||
|
image= None
|
||||||
"""
|
"""
|
||||||
# TODO: add dynamic image to product
|
# TODO: write image to S3 storage
|
||||||
response = requests.get(self.logo_url)
|
response = requests.get(self.logo_url)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
response.raw.decode_content = True
|
response.raw.decode_content = True
|
||||||
image = response.raw
|
image = response.raw
|
||||||
else:
|
else:
|
||||||
image= None
|
logging.warning(f"Got {response.status_code} querying {self.logo_url}")
|
||||||
"""
|
"""
|
||||||
product = ProductFactory(name=name, description=description,)
|
|
||||||
|
product = ProductFactory(name=name, description=description, image=image)
|
||||||
logging.debug(f"New Product {product.name} created")
|
logging.debug(f"New Product {product.name} created")
|
||||||
print(".", end = '')
|
print("*", end = '.')
|
||||||
print('')
|
print('')
|
||||||
|
|
||||||
print("Dataset creation finished")
|
print("Dataset creation finished")
|
||||||
Reference in New Issue
Block a user