Home > Django > Initial DB data

Initial DB data

September 2nd, 2008 Leave a comment Go to comments

Within your application on the same level as your models place a folder named “fixtures”

In my current setup that means “app/models/fixtures/”, but in a normal setup that would be “app/fixtures/”

Within that file all you need to do is add a file with the extension “xml” or “json”. The syntax looks a lot nicer for “json”:

[
{
"model": "app_name.model_name",
"pk": 1,
"fields": {
"name": "A",
"value": 5
}
},
{
"model": "app_name.model_name",
"pk": 3,
"fields": {
"name": "C",
"value": 15
}
}
]

When you’re all set with your data all you need to do is run “python manage.py loaddata json_filename” (leaving off the “json” extension)

Categories: Django Tags:
  1. No comments yet.
  1. No trackbacks yet.