T-HL Django object models

Data initialization

Bruno Stuyts

These instructions are meant as a bare bones getting started to get up and running with a new database:

With the correct settings, we can start by migrating existing core and 3rd party apps:

$ python manage.py migrate

Next, the migrations for the project apps can be created:

$ python manage.py makemigrations
$ python manage.py migrate

Now, we need to load data for django-cities:

$ python manage.py cities --import=all

To import airport data, we temporarily need to downgrade Django:

$ conda install django=1.9
$ python manage.py airports
$ conda install django=1.10

Importing currencies is possible thanks to the django-currencies app. Note that this app needs to be cloned and install from source. Installation with pip will not provide the correct version. To import currencies, use the following command: 

$ python manage.py currencies --import=USD --import=EUR --import=GBP

If this import fails, you can manually add the currencies in the database with pgAdmin.

The exchange rate update happens with:

$ python manage.py updatecurrencies oxr --base=EUR

This provides a full dataset to get started with.

In order to avoid importing from the web, fixtures can be created as follows:

$ python manage.py dumpdata airports > airports.json

This exports all airports data to a .json file which can be loaded with the following command. More details are provided in this post.

$ python manage.py loaddata airports.json

Note that a dump to XML is also possible with the following command:

$ python manage.py dumpdata auth.user --indent 2 --format xml > user.xml