Fakultas Ilmu Komputer UI

Commit 90bb3dc4 authored by Nabila Febri Viola's avatar Nabila Febri Viola
Browse files

[GREEN] Add arguments for acara donor seeder

parent 5d6adb75
import random
from django.core.management.base import BaseCommand
from django.core.management.base import BaseCommand, CommandError
from main.models import User
from acara_donor.factories import AcaraDonorFactory
from main.factories import UserFactory
class Command(BaseCommand):
help = 'Seeds the database.'
help = 'Seeds the database with dummy acara donor.'
def add_arguments(self, parser):
parser.add_argument('--users_emails', nargs='+', type=str)
def handle(self, *args, **options):
list_user = []
for _ in range(33):
user = UserFactory()
user.save()
list_user.append(user)
for _ in range(123):
i = random.randint(0, 32) # NOSONAR
AcaraDonorFactory(user=list_user[i])
self.stdout.write(self.style.SUCCESS("Successfully seeds the database with dummy acara donor."))
if not options['users_emails']:
for _ in range(33):
user = UserFactory()
user.save()
list_user.append(user)
else:
for email in options['users_emails']:
try:
list_user.append(User.objects.get(email=email))
except User.DoesNotExist:
raise CommandError(f"User {email} does not exist.")
for i in range(len(list_user)):
amount = random.randint(0, 32) # NOSONAR
for _ in range(amount):
AcaraDonorFactory(user=list_user[i])
self.stdout.write(
self.style.SUCCESS(
"Successfully seeds the database with dummy acara donor."))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment