From 1a419c01172ef00b29bc0bbfc39766d9ecccfa18 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 20 Feb 2020 16:11:17 +0000 Subject: new migrationjs and generate_people command working --- .../management/commands/generate_people.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ctrack/organisations/management/commands/generate_people.py') diff --git a/ctrack/organisations/management/commands/generate_people.py b/ctrack/organisations/management/commands/generate_people.py index d61902e..d429438 100644 --- a/ctrack/organisations/management/commands/generate_people.py +++ b/ctrack/organisations/management/commands/generate_people.py @@ -1,4 +1,9 @@ from django.core.management import BaseCommand +from django.core.management import CommandParser + +from ctrack.organisations.tests.factories import PersonFactory +from ctrack.organisations.tests.factories import RoleFactory +from ctrack.organisations.tests.factories import UserFactory class Command(BaseCommand): @@ -8,6 +13,20 @@ class Command(BaseCommand): python manage.py generate_people """ + def add_arguments(self, parser: CommandParser) -> None: + parser.add_argument("number", nargs=1, type=int) + + 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 + 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) -- cgit v1.2.3