Framework

Generate Test Data for Django with the MockHero API

The Problem

Django has a built-in fixtures system, but maintaining JSON fixture files is painful. They rot as your models change, and the data inside them is usually lorem ipsum that does not help you build a convincing demo or catch real bugs.

Libraries like Factory Boy help, but they require defining a factory class for every model. For a project with 15 models, that is 15 factory classes to write and maintain.

The Solution: MockHero API

MockHero generates realistic data from a simple HTTP call. Define your Django models as a MockHero schema, hit the API, and write the JSON into your database through the ORM. No libraries to install on the Python side beyond requests.

Quick Setup

curl -X POST https://api.mockhero.dev/api/v1/generate \
  -H "x-api-key: mh_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
  "tables": [
    {
      "name": "authors",
      "count": 5,
      "fields": [
        { "name": "id", "type": "uuid" },
        { "name": "name", "type": "full_name" },
        { "name": "email", "type": "email" },
        { "name": "bio", "type": "paragraphs" }
      ]
    },
    {
      "name": "articles",
      "count": 20,
      "fields": [
        { "name": "id", "type": "uuid" },
        { "name": "author_id", "type": "ref", "params": { "ref": "authors.id" } },
        { "name": "title", "type": "sentence" },
        { "name": "body", "type": "paragraphs" },
        { "name": "published_at", "type": "datetime" }
      ]
    }
  ],
  "format": "json"
}'

Step-by-Step Guide

1. Install dependencies

pip install requests

2. Get your MockHero API key

Sign up at mockhero.dev/sign-up.

3. Create a management command

Create myapp/management/commands/seed.py that calls the MockHero API and uses Django ORM to insert the returned records.

4. Run the command

python manage.py seed

5. Verify in Django admin

Open /admin/ and browse your models. All articles reference valid authors.

Complete Example

The management command pattern works for any Django project. It fetches data from MockHero and inserts it through the ORM, handling relationships via ref fields.

Why MockHero vs Factory Boy / Fixtures

  • No factory classes — define schemas in JSON, not Python classes.
  • Always fresh — no stale fixture files to update when models change.
  • Language-agnostic — the same API works for your Django backend and React frontend.

Get Started

Free tier, 1,000 rows/month. Sign up at mockhero.dev and run python manage.py seed in minutes.

M

MockHero Team

Guides and tutorials for generating realistic test data with the MockHero API.

Start generating test data for free

1,000 rows/month on the free tier. No credit card required.

Get Your API Key

Related Articles