Updated sample data creation

This commit is contained in:
Harry Bridge
2019-01-08 00:22:46 +00:00
parent f24a510a8e
commit 905eea7792
2 changed files with 8 additions and 10 deletions

View File

@@ -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()
user.save()

View File

@@ -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),