Generating fake articles and comments
After defining the database from the models, we are going to generate random data that we will use to work more comfortably.
We create make_fake_data.py
with the following content:
from app.website.models import Post, Comment from faker import Faker # Delete all posts and comments Post.objects.all().delete() # Create fake object fake = Faker() def get_full_name(): return f"{fake.first_name()} {fake.last_name()}" # Create 30 posts for _ in range(30): post = Post( title=fake.sentence()[:200], content=fake.text(), author=get_full_name()[:20], ) post.save() # Create 150 comments for _ in range(150): comment = Comment( ...