Django Friends Meetup, 2014-03-25
they're not that bad!
Florian Demmer (@fdemmer)
partial database dumps
via django apps/models
serialization: json, yaml, xml
initial state & "configuration"
sample data for designers
and programmers
dropdb and back up in seconds
works offline
[ { "pk": 1, "model": "auth.group", "fields": { "name": "content_editor", "permissions": [ [ "add_article", "content", "article" ], ...
manage.py dumpdata > {file}
manage.py loaddata {name}
fixtures directory, eg. app/fixtures
additional via settings.FIXTURE_DIRS
eg. sample_data
app1/fixtures/sample_data.json
app2/fixtures/sample_data.xmlspecial.
loaded automatically by syncdb & migrate
every time.
(up to 1.6)
to avoid --no-initial-data
(new in 1.5)
https://docs.djangoproject.com/en/dev/releases/1.7/
"initial_data fixtures are no longer loaded for apps with migrations; if you want to load initial data for an app, we suggest you do it in a migration."
initial_data
whatever is save to overwrite every time.
no: defaults, examples, test data, ...
yes: permission groups, automatically updated data, ...
sample_data, test_data
create fixtures, called like what they are!
initial_*
created once, updated by user/customer
manage.py loaddata initial_data
manage.py loaddata sample_data
...
manage.py loaddata initial_exchangerates
...
primary keys are dumped
foreign keys are dumped
default is ugly
{"pk": 1, "model": "auth.group", "fields": {"name": "content_editor", "permissions": [161, 163, 164, 165, 157, 158, 172,
...
manage.py dumpdata --indent 4 --natural
[ { "pk": 1, "model": "auth.group", "fields": { "name": "content_editor", "permissions": [ [ "add_article", "content", "article" ], ...
indent for readability
formatting for git
valid json (no trailing ,)
natural keys to work with dbs with
different primary keys!
(eg. permissions)