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
- [Django]-Is it possible to include a custom 404 view for a Django app without changing anything at the project level?
- [Django]-Django 1.5 gunicorn workers eats memory
- [Django]-Disadvantages of sharing Django sessions on multiple subdomains
- [Django]-JSON Response from Django in Android
- [Django]-Error in django interactive shell on pydev eclipse
Source:stackexchange.com