Django Fixtures

By: Dusty Arlia
Published on Friday, April 11, 2014, 03:16 PM
Last Updated on Tuesday, July 07, 2015 at 10:15 PM
Total Updates: 2

A fixture is a collection of data that Django knows how to import into a database. The fixture is often a JSON file, but can be some other supported file serialization formats (e.g. XML and YAML).

Here is an example fixture for a Persom model:

[
  {
    "model": "your_app.person",
    "pk": 1,
    "fields": {
      "first_name": "Jamie",
      "last_name": "Foxx"
    }
  },
  {
    "model": "your_app.person",
    "pk": 2,
    "fields": {
      "first_name": "Leonardo",
      "last_name": "DiCaprio"
    }
  }
]

Fixtures like this are stored in a fixtures directory inside your app.

Comments:

Ad:

Ad: