I would like to import data into a Django project regularly. I need to tell the provider of my data what formats I want to received the data in. Should I ask for it in Json, XML, CSV ?
How does one usually deal with this in Django?
Django has a whole framework for importing data called Fixtures. You can read about the available formats (JSON is definitely there) here: https://docs.djangoproject.com/en/dev/howto/initial-data/
There are also examples of what the data should look like. Such as:
[
{
"model": "myapp.person",
"pk": 1,
"fields": {
"first_name": "John",
"last_name": "Lennon"
}
},
{
"model": "myapp.person",
"pk": 2,
"fields": {
"first_name": "Paul",
"last_name": "McCartney"
}
}
]
If you saved that as beatles.json, you could import it by running python manage.py loaddata /path/to/beatles.json
If you want to support CSV or XML, I would advice to use django-adaptors
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With