aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/organisations/management/commands/generate_people.py
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-02-20 16:11:17 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2020-02-20 16:11:17 +0000
commit1a419c01172ef00b29bc0bbfc39766d9ecccfa18 (patch)
tree322bd02eab60828ecb399d40e820ec1733a93364 /ctrack/organisations/management/commands/generate_people.py
parent286c6bfc65636f57f29b4d4f9a45de5218c62cfe (diff)
new migrationjs and generate_people command working
Diffstat (limited to 'ctrack/organisations/management/commands/generate_people.py')
-rw-r--r--ctrack/organisations/management/commands/generate_people.py19
1 files changed, 19 insertions, 0 deletions
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)