From 208f96add7cce65de7f3d0c09fe332b333ddc318 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 10 Feb 2021 13:52:39 +0000 Subject: [PATCH] changes to addtestdata --- core/management/commands/addtestdata.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/core/management/commands/addtestdata.py b/core/management/commands/addtestdata.py index 7618363..cd6a431 100644 --- a/core/management/commands/addtestdata.py +++ b/core/management/commands/addtestdata.py @@ -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") \ No newline at end of file