I create a web application with Django and I need basic data. To do this, I have a JSON that contains a lot of data that I would like to import into my Django database.
So I'm looking for a way to import this data without modifying the JSON file.
Extract from JSON:
[
{
"key": "sword",
"name": "Sword",
"tier": 1
},
{
"key": "bow",
"name": "Bow",
"tier": 1
},
...
]
My file contains a lot of data and it would take a long time to change it. Is there a script / program to import all this data corresponding to the following model:
from django.db import models
class Item(models.Model):
name = models.CharField(max_length=120)
tier = models.PositiveIntegerField()
I saw the example on the django site, but it would be necessary to add to each item in my JSON a property model which would be very long
Example from Django website:
[
{
"model": "myapp.person",
"pk": 1,
"fields": {
"first_name": "John",
"last_name": "Lennon"
}
},
{
"model": "myapp.person",
"pk": 2,
"fields": {
"first_name": "Paul",
"last_name": "McCartney"
}
}
]