changes to addtestdata

This commit is contained in:
Sam
2021-01-26 14:05:39 +00:00
parent 9b78fba142
commit d94eb9882c

View File

@@ -1,6 +1,8 @@
import logging import logging
import json import json
import requests
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.contrib.gis.geos import GEOSGeometry, MultiPolygon from django.contrib.gis.geos import GEOSGeometry, MultiPolygon
@@ -19,6 +21,8 @@ logging.basicConfig(
class Command(BaseCommand): class Command(BaseCommand):
logo_url = "https://picsum.photos/200/300"
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
print("Creating fake data to populate database") print("Creating fake data to populate database")
@@ -47,7 +51,18 @@ class Command(BaseCommand):
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)
product = ProductFactory(name=name, description=description) # TODO: apply tags from tag list
"""
# TODO: add dynamic image to product
response = requests.get(self.logo_url)
if response.status_code == 200:
response.raw.decode_content = True
image = response.raw
else:
image= None
"""
product = ProductFactory(name=name, description=description,)
logging.debug(f"New Product {product.name} created") logging.debug(f"New Product {product.name} created")
print(".", end = '') print(".", end = '')
print('') print('')