[Django]-Good ways to import data into Django

12👍

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

1👍

If you want to support CSV or XML, I would advice to use django-adaptors

👤trez

Leave a comment