import random import uuid from django.utils.text import slugify from faker import Faker from api.models import BlogPost, Review fake = Faker() TITLES = ['10 Tips for Healthier Soil This Spring', 'Inside the Studio: Crafting the Perfect Ceramic Bowl', 'Why Local Produce Actually Tastes Better', 'Restoring Heritage: Traditional Blacksmithing', 'Seasonal Eating Guide: Winter Root Vegetables', 'Sustainable Farming: Organic Certification', 'Community Spotlight: Heritage Valley Market', 'DIY Garden Shed: A Step-by-Step Guide'] CATEGORIES = ['farming', 'artisanship', 'faith', 'sustainability', 'market-updates'] TOPICS = {'farming': 'farm,agriculture', 'artisanship': 'handicraft,pottery', 'faith': 'church,community', 'sustainability': 'ecology,nature', 'market-updates': 'market,vegetables'} def create_articles(command, sellers): command.stdout.write('Seeding article hub...') for index, title in enumerate(TITLES): if not sellers: break category = random.choice(CATEGORIES) try: BlogPost.objects.create(title=title, slug=f'{slugify(title)}-{uuid.uuid4().hex[:4]}', excerpt=fake.sentence(nb_words=20), content=''.join(f'

{p}

' for p in fake.paragraphs(nb=6)), category=category, author=random.choice(sellers), featured=index < 3, image=f'https://loremflickr.com/1200/800/{TOPICS[category]}?random={random.randint(1,1000)}', published=True) except Exception as error: command.stdout.write(command.style.ERROR(f'Failed to create article {title}: {error}')) def create_reviews(products, buyer): for product in products: for _ in range(random.randint(1, 2)): try: Review.objects.create(product=product, reviewer=buyer, rating=random.randint(4, 5), title=random.choice(['Excellent quality!', 'Great value', 'Highly recommend', 'Solid product']), comment=fake.sentence(nb_words=15)) except Exception: continue