From 2aebf2ada898385b0f648b11a261a2d7a9d2dbef Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 20 Feb 2020 16:19:26 +0000 Subject: tidied up the management command --- .../management/commands/generate_people.py | 25 +++++----------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'ctrack/organisations/management/commands') diff --git a/ctrack/organisations/management/commands/generate_people.py b/ctrack/organisations/management/commands/generate_people.py index d429438..53ece21 100644 --- a/ctrack/organisations/management/commands/generate_people.py +++ b/ctrack/organisations/management/commands/generate_people.py @@ -10,7 +10,7 @@ class Command(BaseCommand): help = """ Creates a bunch of people and organisations for them to work in. - python manage.py generate_people + Also creates users and roles as these are required fields. """ def add_arguments(self, parser: CommandParser) -> None: @@ -18,27 +18,12 @@ class Command(BaseCommand): def handle(self, *args, **options): number = options["number"][0] - # Let's use the factory to create people (and organisations, a user and role as a by-product) - user = UserFactory.create() - role = RoleFactory.create() # all these people get the role for now - PersonFactory.create_batch(number, role=role, updated_by=user, predecessor=None) # predecessor is too hard at the moment + user = UserFactory.create() # we need to have at least one user for the updated_by field + role = RoleFactory.create() # because we have a many-to-many relationship with Role, we need to create one and pass it in + PersonFactory.create_batch(number, role=role, updated_by=user, + predecessor__predecessor=None) # we do this so we don't get a loop self.stdout.write( self.style.SUCCESS( f"Created {number} Person object[s]! Go forth and multiply." ) ) - -# def add_arguments(self, parser): -# parser.add_argument("year", nargs="+", type=int) -# -# def handle(self, *args, **options): -# for opt in options["year"]: -# FinancialQuarter.objects.create(quarter=1, year=opt) -# FinancialQuarter.objects.create(quarter=2, year=opt) -# FinancialQuarter.objects.create(quarter=3, year=opt) -# FinancialQuarter.objects.create(quarter=4, year=opt) -# self.stdout.write( -# self.style.SUCCESS( -# f"Created FinancialQuarter objects for the years: {opt}" -# ) -# ) -- cgit v1.2.3