You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.7 KiB
71 lines
2.7 KiB
from server.api.models import Transaction, Account, User, Stack |
|
from django.core.management.base import BaseCommand |
|
|
|
import sys |
|
import itertools |
|
import random |
|
random.seed(123) |
|
|
|
class Command(BaseCommand): |
|
help = 'Seed database for dev' |
|
|
|
def handle(self, *args, **options): |
|
self.stdout.write('Clearing and seeding database...') |
|
|
|
User.objects.all().delete() |
|
elijah = User.objects.create(username='elijah', email='elijah@westwinds.io', password='toffee15') |
|
ievgen = User.objects.create(username='ievgen', email='ievgen@westwinds.io', password='toffee15') |
|
tanner = User.objects.create(username='tanner', email='tanner@westwinds.io', password='toffee15') |
|
|
|
self.stdout.write(str(User.objects.all())) |
|
self.stdout.write('{} users created!'.format(User.objects.count())) |
|
|
|
|
|
Account.objects.all().delete() |
|
Stack.objects.all().delete() |
|
Transaction.objects.all().delete() |
|
account_count = 1 |
|
|
|
self.stdout.ending = '' |
|
self.stdout.write('Populating data') |
|
|
|
for length in range(1,4): |
|
for users in itertools.combinations([elijah, ievgen, tanner], length): |
|
income = random.randint(2000,4000) |
|
expenses = random.randint(1000, income) |
|
|
|
account = Account.objects.create( |
|
name='Account #{}'.format(account_count), |
|
details='Belongs to {}'.format(', '.join([u.username for u in users])), |
|
income=income, |
|
expenses=expenses, |
|
) |
|
account.users.set(users) |
|
account.save() |
|
|
|
for stack_num in range(1, random.randint(2, 7)): |
|
stack = Stack.objects.create( |
|
account=account, |
|
name='Stack #{}'.format(stack_num), |
|
details='Belongs to account #{}'.format(account_count), |
|
amount=random.randint(100, expenses), |
|
) |
|
|
|
for tx_num in range(1, random.randint(2, 50)): |
|
tx = Transaction.objects.create( |
|
stack=stack, |
|
#name='Transaction #{}'.format(tx_num), |
|
details='Belongs to stack #{}'.format(stack_num), |
|
amount=random.randint(1, 100), |
|
) |
|
|
|
self.stdout.write('.') |
|
sys.stdout.flush() |
|
|
|
account_count += 1 |
|
|
|
self.stdout.ending = '\n' |
|
self.stdout.write('') |
|
self.stdout.write('{} accounts created!'.format(Account.objects.count())) |
|
|
|
self.stdout.write('done!')
|
|
|