changes to addtestdata

This commit is contained in:
Sam
2021-02-10 13:52:39 +00:00
parent 02f6b29e5f
commit 208f96add7

View File

@@ -9,7 +9,9 @@ from django.contrib.gis.geos import GEOSGeometry, MultiPolygon
from faker import Faker
from companies.factories import CompanyFactory
from companies.models import Company
from products.factories import ProductFactory
from products.models import Product
logging.basicConfig(
@@ -25,7 +27,11 @@ class Command(BaseCommand):
help = 'Creates fake companies and related products in database'
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
fake = Faker()
@@ -40,31 +46,34 @@ class Command(BaseCommand):
company = CompanyFactory(company_name=name)
new_companies.append(company)
logging.debug(f"New Company {company.company_name} created")
print(".", end = '')
print(f"\t- {name}")
print('')
logging.info("Creating fake products")
print("Creating fake products")
# create and assign products to 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):
name = fake.last_name_nonbinary()
description = fake.paragraph(nb_sentences=5)
# 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)
if response.status_code == 200:
response.raw.decode_content = True
image = response.raw
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")
print(".", end = '')
print("*", end = '.')
print('')
print("Dataset creation finished")