moved data files to datasets/, created addtestdata command
This commit is contained in:
@@ -26,12 +26,12 @@ class Command(BaseCommand):
|
|||||||
# create country for spain
|
# create country for spain
|
||||||
country = Country.objects.create(name='España')
|
country = Country.objects.create(name='España')
|
||||||
|
|
||||||
locations_file = 'locations.json'
|
locations_file = 'datasets/locations.json'
|
||||||
locations = json.loads(open(locations_file).read())
|
locations = json.loads(open(locations_file).read())
|
||||||
|
|
||||||
# REGIONS
|
# 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())
|
geo_data = json.loads(open(geo_file).read())
|
||||||
|
|
||||||
logging.info("Starting Region creation")
|
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")
|
||||||
@@ -7,4 +7,5 @@ django-filter==2.4.0
|
|||||||
-e git://github.com/darklow/django-suit/@v2#egg=django-suit
|
-e git://github.com/darklow/django-suit/@v2#egg=django-suit
|
||||||
django-cors-headers==3.5.0
|
django-cors-headers==3.5.0
|
||||||
django-taggit-serializer==0.1.7
|
django-taggit-serializer==0.1.7
|
||||||
django-tagulous==1.1.0
|
django-tagulous==1.1.0
|
||||||
|
faker==5.7.0
|
||||||
Reference in New Issue
Block a user