diff --git a/core/management/commands/addgeo.py b/core/management/commands/addgeo.py index 6d47e05..4f9f92b 100644 --- a/core/management/commands/addgeo.py +++ b/core/management/commands/addgeo.py @@ -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") diff --git a/core/management/commands/addtestdata.py b/core/management/commands/addtestdata.py new file mode 100644 index 0000000..55f035f --- /dev/null +++ b/core/management/commands/addtestdata.py @@ -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") \ No newline at end of file diff --git a/gadm36_ESP.json b/datasets/gadm36_ESP.json similarity index 100% rename from gadm36_ESP.json rename to datasets/gadm36_ESP.json diff --git a/locations.json b/datasets/locations.json similarity index 100% rename from locations.json rename to datasets/locations.json diff --git a/requirements.txt b/requirements.txt index 0e62195..4142296 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,5 @@ django-filter==2.4.0 -e git://github.com/darklow/django-suit/@v2#egg=django-suit django-cors-headers==3.5.0 django-taggit-serializer==0.1.7 -django-tagulous==1.1.0 \ No newline at end of file +django-tagulous==1.1.0 +faker==5.7.0 \ No newline at end of file