Overview
Thecreate_random_data management command generates random pages, snippets, and images for the Wagtail Bakery Demo. This command is particularly useful for performance testing, load testing, and testing the application with large datasets.
This command requires that initial data has already been loaded using
load_initial_data, as it depends on existing index pages and reference data.Usage
Command Arguments
The number of pages of each type to create. The command will create this many:
- Bread pages under the Breads index
- Location pages under the Locations index
- Blog pages under the Blog index
- Standard pages (nested under a new top-level standard page)
The number of snippets of each type to create:
- Countries
- Bread Ingredients
- Bread Types
- People
- Footer Text
The number of random images to create in the Wagtail image library. Images are randomly selected from the fixture media directory.
Examples
Create Small Dataset
Generate 10 pages, 5 snippets, and 20 images:Create Large Dataset for Load Testing
Generate 100 pages, 50 snippets, and 200 images:Minimal Data for Development
Generate just a few items:What It Creates
The command generates three types of content:Images
Creates random images by selecting from existing fixture media files. Each image gets:
- Random title (4 words from Lorem Ipsum)
- Proper dimensions extracted from the source image
- File size metadata
Snippets
Creates random snippets across all types:
- Countries: Geographic origins for breads
- Bread Ingredients: Components used in recipes
- Bread Types: Categories of bread
- People: Staff members with names and job titles
- Footer Text: Rich text content blocks
Generated Content Details
Page Content
All pages are created with realistic content:- Titles: 4-word titles generated from Lorem Ipsum
- Slugs: Automatically generated from titles
- Introductions: Single paragraph of Lorem Ipsum
- Body Content: StreamField with 5 paragraphs of rich text
- Images: Randomly selected from the image library
- Dates: Current timestamp for blog posts
Example Output
Source Code Location
bakerydemo/base/management/commands/create_random_data.py
Implementation Details
Random Data Generation
The command uses Django’s built-inlorem_ipsum utility for realistic text:
Random Model Selection
When creating pages that need relationships (e.g., bread origin), the command randomly selects existing models:Image Source
Images are created from files in:Performance Considerations
Database Impact
Each argument multiplies the data created:page_count=10: Creates 40 pages (10 × 4 page types)snippet_count=10: Creates 50 snippets (10 × 5 snippet types)image_count=10: Creates 10 images
Recommended Limits
| Use Case | page_count | snippet_count | image_count |
|---|---|---|---|
| Development | 5-10 | 3-5 | 10-20 |
| Load Testing | 100-500 | 50-100 | 100-200 |
| Stress Testing | 1000+ | 500+ | 500+ |
Prerequisites
Related Commands
load_initial_data- Load initial fixture data (required first)reset_demo- Reset database and remove all random data
Troubleshooting
”NoneType object has no attribute” errors
This usually means index pages don’t exist. Runload_initial_data first:

