Populating table with external data
@django @json
Sometimes, with models that are intended t be static (i.e. Grade model in MTNPAK) we want to be able to populate the table with the final static values before deployment. Conversely, we sometimes want to dump the data from an existing table in JSON format. This section describes how to do that.
Dumping existing table
To dump all the data in an existing table, do:
python3 manage.py dumpdata [app.Model] --indent 4
Where [app.Model] is something like routes.Route.
Then, copy the outputted data and copy to:
project/appname/fixtures/[filename].json
When you load data, it will look in the fixtures directory by default.
Loading data to a table
To load data from an external source (i.e. a file called dumpdata.json):
python3 manage.py loaddata [filename].json