Can I perform a dumpdata
in Django on just a single model, rather than the whole app, and if so, how?
For an app it would be:
python man
I think you had the solution in your question. You can dump an individual model like this:
./manage.py dumpdata myapp.my_model
As of version 1.1 and greater, the Django dumpdata management command allows you to dump data from individual tables:
./manage.py dumpdata myapp1 myapp2.my_model
You can also separate multiple apps and models on the command line. Here's the canonical definition:
django-admin dumpdata [app_label[.ModelName] [app_label[.ModelName] ...]]
To write it on specific file:
python manage.py dumpdata app_label.ModelName app_label.ModelName2 > fixtures/specic.json
If you want to dump only the specified objects of a model, you can use the --pks optional argument for the dumpdata command.
--pks PRIMARY_KEYS Outputs only the objects specified by a comma separated list of primary keys. This is only available when dumping one model. By default, all the records of the model are output.
For success I had to say it twice, and specify the model two times, like:
./manage.py dumpdata myapp2.my_model myapp2.my_model
If I only said
./manage.py dumpdata myapp2 myapp2.my_model
I got flooded with all the models in myapp2, despite the fact that I specified my_model.
As a workaround you could make another app and copy the model but point it to the existing table with the db_table meta option. Then you could just dump the models you copied into the new app. You existing app wouldn't be affected.