Dayozoe's picture
feat: deploy HarvestConnect Django API with crash-proof persistent volume
a6be783 verified
Raw History Blame Contribute Delete
1.26 kB
from api.factories import CategoryFactory, UserFactory, ProductFactory
from api.models import UserProfile
def create_categories(command, count):
command.stdout.write('Creating categories...')
items = CategoryFactory.create_batch(count)
command.stdout.write(command.style.SUCCESS(f'✓ Created {len(items)} categories'))
return items
def create_users(command, count):
command.stdout.write('Creating users and profiles...')
users = []
for _ in range(count):
user = UserFactory.create()
UserProfile.objects.get_or_create(user=user)
users.append(user)
command.stdout.write(command.style.SUCCESS(f'✓ Created {len(users)} users with profiles'))
return users
def create_products(command, users, categories, count):
command.stdout.write('Creating products...')
products = []
for index in range(count):
seller = users[index % len(users)]
profile, _ = UserProfile.objects.get_or_create(user=seller)
profile.role = 'seller'
profile.save()
products.append(ProductFactory.create(seller=seller, category=categories[index % len(categories)]))
command.stdout.write(command.style.SUCCESS(f'✓ Created {len(products)} products'))
return products