Skip to main content
The Bakery Demo includes several custom management commands to help you work with the demo data, test performance, and maintain your development environment.

Overview

All management commands are located in bakerydemo/base/management/commands/ and can be run using:
./manage.py <command_name> [options]

Available Commands

load_initial_data

Load demo fixtures and media files

create_random_data

Generate random content for testing

reset_demo

Reset demo to initial state

reset_admin_password

Update admin password from settings

load_initial_data

Loads the initial demo data including pages, images, snippets, and media files.

Usage

./manage.py load_initial_data

What It Does

1

Copy Media Files

Recursively copies media files from bakerydemo/base/fixtures/media to your configured storage backend.
local_storage = FileSystemStorage(os.path.join(fixtures_dir, "media"))
self._copy_files(local_storage, "")
This works with both local file storage and cloud providers like S3.
2

Clean Default Content

Removes the auto-generated default Site and Page instances that Wagtail creates during installation:
if Site.objects.filter(hostname="localhost").exists():
    Site.objects.get(hostname="localhost").delete()
if Page.objects.filter(title="Welcome to your new Wagtail site!").exists():
    Page.objects.get(title="Welcome to your new Wagtail site!").delete()
3

Load Fixtures

Loads the demo data from bakerydemo/base/fixtures/bakerydemo.json:
call_command("loaddata", fixture_file, verbosity=0)
4

Update Indexes

Rebuilds the search and reference indexes:
call_command("update_index", verbosity=0)
call_command("rebuild_references_index", verbosity=0)

Example Output

Copying media files to configured storage...
Awesome. Your data is loaded! The bakery's doors are almost ready to open...

Use Cases

  • Initial project setup
  • Restoring demo data after testing
  • Setting up a new environment
  • Resetting to a known good state
This command is automatically called by reset_demo after resetting the database.

create_random_data

Generates random pages, snippets, and images for performance testing and load testing.

Usage

./manage.py create_random_data <page_count> <snippet_count> <image_count>

Arguments

page_count
integer
required
Number of pages of each type to create (blog, bread, location, standard)
snippet_count
integer
required
Number of snippets of each type to create (countries, ingredients, bread types, people, footer text)
image_count
integer
required
Total number of images to create

Examples

# Create 10 pages, 5 snippets, and 20 images
./manage.py create_random_data 10 5 20

What It Creates

Bread Pages (page_count items)
BreadPage(
    title=lorem_ipsum.words(4, common=False),
    introduction=lorem_ipsum.paragraph(),
    bread_type=random_bread_type,
    body=fake_stream_field(),
    origin=random_country,
    image=random_image,
)
Location Pages (page_count items)
LocationPage(
    title=lorem_ipsum.words(4, common=False),
    introduction=lorem_ipsum.paragraph(),
    image=random_image,
    address=lorem_ipsum.paragraph(),
    body=fake_stream_field(),
    lat_long="64.144367, -21.939182",
)
Blog Pages (page_count items)
BlogPage(
    title=lorem_ipsum.words(4, common=False),
    introduction=lorem_ipsum.paragraph(),
    body=fake_stream_field(),
    subtitle=lorem_ipsum.words(10, common=False),
    date_published=timezone.now(),
)
Standard Pages (page_count + 1 items)Creates one top-level page and page_count child pages nested under it.
For each snippet type, creates snippet_count items:
  • Countries: Random country names
  • Bread Ingredients: Random ingredient names
  • Bread Types: Random bread type names
  • People: Random person with first name, last name, job title, and image
  • Footer Text: Random footer content
Creates image_count images by randomly selecting from fixtures:
# Source images from
FIXTURE_MEDIA_DIR = "bakerydemo/base/fixtures/media/original_images"

# Each image includes:
Image.objects.create(
    title=random_title,
    width=image_width,
    height=image_height,
    file_size=file_size,
)

Example Output

Creating images...
Creating countries...
Creating bread ingredients...
Creating bread types...
Creating people...
Creating footer text...
Creating bread pages...
Creating location pages...
Creating blog pages...
Creating standard pages...

Use Cases

  • Performance Testing: Generate large datasets to test page load times
  • Load Testing: Create thousands of pages to test server capacity
  • UI Testing: Test pagination, filtering, and search with lots of content
  • Database Optimization: Test query performance with realistic data volumes
Generating large datasets (e.g., 1000+ pages) can take several minutes and significantly increase database size.

reset_demo

Resets the entire demo to its initial state by wiping the database and reloading fixtures.

Usage

./manage.py reset_demo
This command is destructive and will delete all data. Only available with PostgreSQL databases.

Requirements

  • PostgreSQL database (will not work with SQLite)
  • django-extensions installed (included in development requirements)

What It Does

1

Validate Database

Ensures you’re using PostgreSQL:
if settings.DATABASES[DEFAULT_DB_ALIAS]["ENGINE"] not in POSTGRESQL_ENGINES:
    raise CommandError(
        "This command can be used only with PostgreSQL databases."
    )
2

Remove Storage Files

Removes all files from S3 or deletes images/documents:
if "s3" in default_storage.__class__.__name__.lower():
    default_storage.bucket.objects.all().delete()
else:
    get_image_model().objects.all().delete()
    get_document_model().objects.all().delete()
3

Reset Database Schema

Drops all tables and recreates the schema:
call_command("reset_schema", interactive=False)
4

Run Migrations

Applies all migrations:
call_command("migrate", interactive=False)
5

Clear Caches

Clears all configured caches:
for cache in caches.all():
    cache.clear()
6

Reload Data

Loads initial demo data:
call_command("load_initial_data")
7

Reset Admin Password

Updates the admin password:
call_command("reset_admin_password")

Example Output

Removing files from S3
Reset schema
Running migrations...
Copying media files to configured storage...
Awesome. Your data is loaded! The bakery's doors are almost ready to open...

Use Cases

  • Reset demo after testing destructive operations
  • Clean slate for demonstrations
  • Fix database corruption issues
  • Prepare staging environment

Alternative for SQLite

If you’re using SQLite, manually reset by:
rm bakerydemodb
./manage.py migrate
./manage.py load_initial_data

reset_admin_password

Updates the admin user’s password to match the ADMIN_PASSWORD setting.

Usage

./manage.py reset_admin_password

What It Does

admin_user = User.objects.get(username="admin")
admin_user.set_password(settings.ADMIN_PASSWORD)
admin_user.save(update_fields=["password"])

Configuration

The password is read from settings (default: “changeme”):
# bakerydemo/settings/base.py
ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "changeme")

Setting a Custom Password

export ADMIN_PASSWORD="your-secure-password"
./manage.py reset_admin_password

Use Cases

  • Synchronize password across environments
  • Reset password after demo sessions
  • Automate deployment scripts
  • Called automatically by reset_demo
This command only updates the password if a user named “admin” exists. It will raise an error if the admin user is not found.

Built-in Django Commands

The demo also uses standard Django and Wagtail management commands:

Database Management

# Run migrations
./manage.py migrate

# Create migrations
./manage.py makemigrations

# Show migrations
./manage.py showmigrations

Search Index

# Update search index
./manage.py update_index

# Rebuild search index
./manage.py rebuild_index

# Rebuild references index
./manage.py rebuild_references_index

User Management

# Create superuser
./manage.py createsuperuser

# Change user password
./manage.py changepassword admin

Data Export

# Export all data
./manage.py dumpdata --natural-foreign --indent 2 \
  -e auth.permission -e contenttypes \
  -e wagtailcore.GroupCollectionPermission \
  -e wagtailimages.rendition -e sessions \
  > backup.json

# Load data
./manage.py loaddata backup.json

Development

# Start development server
./manage.py runserver

# Run tests
./manage.py test

# Open Django shell
./manage.py shell

# Show project URLs
./manage.py show_urls

Common Workflows

Fresh Start

# Reset everything to initial state
rm bakerydemodb
./manage.py migrate
./manage.py load_initial_data
./manage.py runserver

Performance Testing

# Load initial data
./manage.py load_initial_data

# Add 100 pages for testing
./manage.py create_random_data 100 50 200

# Test search performance
./manage.py update_index

Demo Preparation

# Reset to clean state (PostgreSQL only)
./manage.py reset_demo

# Or manually (SQLite)
rm bakerydemodb
./manage.py migrate
./manage.py load_initial_data

Tips and Best Practices

Always ensure your virtual environment is activated:
source .venv/bin/activate  # macOS/Linux
.venv\Scripts\activate.bat  # Windows
Add -v 2 or -v 3 for more detailed output:
./manage.py migrate -v 2
./manage.py load_initial_data -v 3
Create a setup script for common workflows:
#!/bin/bash
./manage.py migrate
./manage.py load_initial_data
./manage.py create_random_data 10 5 20
./manage.py runserver
Always backup data before running reset commands:
./manage.py dumpdata > backup.json
./manage.py reset_demo

Next Steps

Customization Guide

Learn how to customize the demo

Project Structure

Understand the codebase layout

Build docs developers (and LLMs) love