aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-02-20 16:19:26 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2020-02-20 16:19:26 +0000
commit2aebf2ada898385b0f648b11a261a2d7a9d2dbef (patch)
treebd9ac662aed6697312fd7b8db2502bca8cb3a062 /ctrack
parent1a419c01172ef00b29bc0bbfc39766d9ecccfa18 (diff)
tidied up the management command
Diffstat (limited to 'ctrack')
-rw-r--r--ctrack/organisations/management/commands/generate_people.py25
1 files changed, 5 insertions, 20 deletions
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}"
-# )
-# )