diff --git a/management/commands/createBaseUsers.py b/management/commands/createBaseUsers.py index 8bf0437a..ba24c508 100644 --- a/management/commands/createBaseUsers.py +++ b/management/commands/createBaseUsers.py @@ -15,7 +15,8 @@ class Command(BaseCommand): self.create_user_object('staff', True) self.create_user_object('basic') - def create_user_object(self, name, staff=False, superuser=False): + @staticmethod + def create_user_object(name, staff=False, superuser=False): user, created = User.objects.get_or_create( username=name, defaults={'email': '{}@{}.com'.format(name, name), 'first_name': name.title(), 'last_name': 'User', 'is_superuser': superuser, @@ -23,4 +24,4 @@ class Command(BaseCommand): if created: user.set_password(name) - user.save() \ No newline at end of file + user.save() diff --git a/management/commands/createSampleData.py b/management/commands/createSampleData.py index 9a5af2e2..e8d4c863 100644 --- a/management/commands/createSampleData.py +++ b/management/commands/createSampleData.py @@ -1,4 +1,5 @@ from django.core.management.base import BaseCommand, CommandError +from django.core.management import call_command from django.utils import timezone import random @@ -11,15 +12,16 @@ class Command(BaseCommand): def handle(self, *args, **kwargs): from django.conf import settings - if not (settings.DEBUG): + if not settings.DEBUG: raise CommandError('You cannot run this command in production') random.seed('Some object to see the random number generator') + call_command('createBaseUsers') + self.create_categories() self.create_statuses() self.create_suppliers() - self.create_collections() self.create_assets() def create_categories(self): @@ -40,12 +42,6 @@ class Command(BaseCommand): for supplier in suppliers: models.Supplier.objects.create(name=supplier) - def create_collections(self): - collections = ['An amp rack', 'Some video thing', 'Ampy patch boxes', 'The noise dept', 'Cable fun zone'] - - for collection in collections: - models.Collection.objects.create(name=collection) - def create_assets(self): assest_description = ['Large cable', 'Shiny thing', 'New lights', 'Really expensive microphone', 'Box of fuse flaps', 'Expensive tool we didn\'t agree to buy', 'Cable drums', 'Boring amount of tape', 'Video stuff no one knows how to use', 'More amplifiers', 'Heatshrink'] @@ -55,6 +51,7 @@ class Command(BaseCommand): for i in range(100): asset = models.Asset.objects.create( + asset_id='{}'.format(i), description=random.choice(assest_description), category=random.choice(categories), status=random.choice(statuses),