parent
bcf65157d0
commit
a9c51a14a4
1 changed files with 51 additions and 31 deletions
@ -1,51 +1,71 @@ |
|||||||
from server.api.models import Transaction, Account, User, Stack |
from server.api.models import Transaction, Account, User, Stack |
||||||
from django.core.management.base import BaseCommand |
from django.core.management.base import BaseCommand |
||||||
|
|
||||||
|
import sys |
||||||
|
import itertools |
||||||
|
import random |
||||||
|
random.seed(123) |
||||||
|
|
||||||
class Command(BaseCommand): |
class Command(BaseCommand): |
||||||
help = "Seed database for dev" |
help = 'Seed database for dev' |
||||||
|
|
||||||
def handle(self, *args, **options): |
def handle(self, *args, **options): |
||||||
self.stdout.write('clearing and seeding database...') |
self.stdout.write('Clearing and seeding database...') |
||||||
|
|
||||||
# create test users |
|
||||||
User.objects.all().delete() |
User.objects.all().delete() |
||||||
elijah = User(username="elijah", |
elijah = User.objects.create(username='elijah', email='elijah@westwinds.io', password='toffee15') |
||||||
email="elijah@westwinds.io", |
ievgen = User.objects.create(username='ievgen', email='ievgen@westwinds.io', password='toffee15') |
||||||
password="toffee15").save() |
tanner = User.objects.create(username='tanner', email='tanner@westwinds.io', password='toffee15') |
||||||
ievgen = User(username="ievgen", |
|
||||||
email="ievgen@westwinds.io", |
|
||||||
password="toffee15").save() |
|
||||||
tanner = User(username="tanner", |
|
||||||
email="tanner@westwinds.io", |
|
||||||
password="toffee15").save() |
|
||||||
|
|
||||||
self.stdout.write(str(User.objects.all())) |
self.stdout.write(str(User.objects.all())) |
||||||
self.stdout.write('Users Created!') |
self.stdout.write('{} users created!'.format(User.objects.count())) |
||||||
|
|
||||||
|
|
||||||
# create an account that all 3 users are attached to |
|
||||||
Account.objects.all().delete() |
Account.objects.all().delete() |
||||||
home = Account(name="home", details="home stacks", |
Stack.objects.all().delete() |
||||||
income=4000, expenses=2000).save() |
Transaction.objects.all().delete() |
||||||
|
account_count = 1 |
||||||
|
|
||||||
self.stdout.write(str(Account.objects.all())) |
self.stdout.ending = '' |
||||||
self.stdout.write('Accounts Created!') |
self.stdout.write('Populating data') |
||||||
|
|
||||||
# create test stacks for account |
for length in range(1,4): |
||||||
Stack.objects.all().delete() |
for users in itertools.combinations([elijah, ievgen, tanner], length): |
||||||
groceries = Stack(name="Groceries", |
income = random.randint(2000,4000) |
||||||
details="", |
expenses = random.randint(1000, income) |
||||||
amount=800).save() |
|
||||||
|
|
||||||
takeout = Stack(name="Date Nights", |
account = Account.objects.create( |
||||||
details="", |
name='Account #{}'.format(account_count), |
||||||
amount=400).save() |
details='Belongs to {}'.format(', '.join([u.username for u in users])), |
||||||
|
income=income, |
||||||
|
expenses=expenses, |
||||||
|
) |
||||||
|
account.users.set(users) |
||||||
|
account.save() |
||||||
|
|
||||||
shit = Stack(name="Crap", |
for stack_num in range(1, random.randint(2, 7)): |
||||||
details="", |
stack = Stack.objects.create( |
||||||
amount=500).save() |
account=account, |
||||||
|
name='Stack #{}'.format(stack_num), |
||||||
|
details='Belongs to account #{}'.format(account_count), |
||||||
|
amount=random.randint(100, expenses), |
||||||
|
) |
||||||
|
|
||||||
Transaction.objects.all().delete() |
for tx_num in range(1, random.randint(2, 50)): |
||||||
# generate transaction history |
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!') |
self.stdout.write('done!') |
||||||
|
Loading…
Reference in new issue