diff options
Diffstat (limited to 'app/dispatch/management/commands/insert_fake_data.py')
| -rw-r--r-- | app/dispatch/management/commands/insert_fake_data.py | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/app/dispatch/management/commands/insert_fake_data.py b/app/dispatch/management/commands/insert_fake_data.py index 81c7b66..0919181 100644 --- a/app/dispatch/management/commands/insert_fake_data.py +++ b/app/dispatch/management/commands/insert_fake_data.py @@ -2,26 +2,24 @@ from django.core.management.base import BaseCommand, CommandError from django.contrib.auth import get_user_model from dispatch.models import Company, Load from faker import Faker -from datetime import date, timedelta import random -# So we can check if a user already exists -from django.core.exceptions import ObjectDoesNotExist from django.db.utils import IntegrityError # import yaml User = get_user_model() + class Command(BaseCommand): help = """Generate fake data.\n Example usage: \n - ./manage.py insert_fake_data --companies 4 --users 3 --loads 800 --start-date='-16w' --end-date '+16w' - """ + ./manage.py insert_fake_data --companies 4 --users 3 --loads 800 + --start-date='-16w' --end-date '+16w' """ fake = Faker() - end_date="" - start_date="" + end_date = "" + start_date = "" def add_arguments(self, parser): # parser.add_argument('--file', type=str, dest='filename') @@ -34,8 +32,8 @@ class Command(BaseCommand): def handle(self, *args, **options): - self.end_date=options['enddate'] - self.start_date=options['startdate'] + self.end_date = options['enddate'] + self.start_date = options['startdate'] company_ids = [] user_ids = [] @@ -61,24 +59,28 @@ class Command(BaseCommand): l = self.fake_load(u, co) - def fake_company(self): new_company = Company( - name = self.fake.company(), - address = self.fake.address(), - phone_number = self.fake.msisdn(), - email_address = self.fake.company_email(), - contact_name = self.fake.name(), + name=self.fake.company(), + address=self.fake.address(), + phone_number=self.fake.msisdn(), + email_address=self.fake.company_email(), + contact_name=self.fake.name(), ) new_company.save() return new_company def fake_load(self, usr, co): + fake_description = "{}-{} {} {}K".format( + self.fake.month(), self.fake.day_of_month(), + self.fake.license_plate(), random.randint(5, 50)) + print(fake_description) new_load = Load( user=usr, # Because that's going to be random enough - load_number=self.fake.license_plate(), - description=self.fake.sentence(nb_words=6), + # load_number=self.fake.license_plate(), + # description=self.fake.sentence(nb_words=6), + description=fake_description, company=co, amount=random.randint(150,2500), delivered_to=self.fake.city(), @@ -95,7 +97,7 @@ class Command(BaseCommand): funame = ffname[0] + flname funame = '%s.%s' % (ffname, flname) - try: + try: new_user = User( first_name=ffname, last_name=flname, @@ -109,4 +111,3 @@ class Command(BaseCommand): except IntegrityError: # Around and around we go until we get something new return self.fake_user() - |
