moved data files to datasets/, created addtestdata command
This commit is contained in:
@@ -26,12 +26,12 @@ class Command(BaseCommand):
|
||||
# create country for spain
|
||||
country = Country.objects.create(name='España')
|
||||
|
||||
locations_file = 'locations.json'
|
||||
locations_file = 'datasets/locations.json'
|
||||
locations = json.loads(open(locations_file).read())
|
||||
|
||||
# REGIONS
|
||||
|
||||
geo_file='gadm36_ESP.json' # geo boundary data for regions
|
||||
geo_file='datasets/gadm36_ESP.json' # geo boundary data for regions
|
||||
geo_data = json.loads(open(geo_file).read())
|
||||
|
||||
logging.info("Starting Region creation")
|
||||
|
||||
55
core/management/commands/addtestdata.py
Normal file
55
core/management/commands/addtestdata.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import logging
|
||||
import json
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.gis.geos import GEOSGeometry, MultiPolygon
|
||||
|
||||
from faker import Faker
|
||||
|
||||
from companies.factories import CompanyFactory
|
||||
from products.factories import ProductFactory
|
||||
|
||||
|
||||
logging.basicConfig(
|
||||
filename='logs/addtestdata.log',
|
||||
filemode='w',
|
||||
format='%(levelname)s:%(message)s',
|
||||
level=logging.INFO,
|
||||
)
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
print("Creating fake data to populate database")
|
||||
|
||||
|
||||
# start faker
|
||||
fake = Faker()
|
||||
Faker.seed(0)
|
||||
|
||||
# companies created
|
||||
new_companies = []
|
||||
logging.info("Creating fake companies")
|
||||
print("Creating fake companies")
|
||||
for i in range(10):
|
||||
name = f"{fake.company()} {fake.company_suffix()}"
|
||||
company = CompanyFactory(company_name=name)
|
||||
new_companies.append(company)
|
||||
logging.debug(f"New Company {company.company_name} created")
|
||||
print(".", end = '')
|
||||
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}")
|
||||
for i in range(100):
|
||||
name = fake.last_name_nonbinary()
|
||||
description = fake.paragraph(nb_sentences=5)
|
||||
product = ProductFactory(name=name, description=description)
|
||||
logging.debug(f"New Product {product.name} created")
|
||||
print(".", end = '')
|
||||
print('')
|
||||
|
||||
print("Dataset creation finished")
|
||||
Reference in New Issue
Block a user