Reputation: 7
I'm tring to convert this json list to django models. but I'm confused. How can I solve this question: Json
[
{
"rank": 1,
"employer": "Walmart",
"employeesCount": 2300000,
"medianSalary": 19177
},
{
"rank": 2,
"employer": "Amazon",
"employeesCount": 566000,
"medianSalary": 38466
}
]
class Persons(models.Model):
rank = models.PositiveIntegerField()
employer = models.CharField(max_length=100)
employeesCount = models.PositiveIntegerField()
medianSalary = models.PositiveIntegerField()
verbose_name = 'Person'
verbose_name_plural = 'Person'
Upvotes: 0
Views: 137
Reputation: 1107
There are multiple ways to achieve this.
fixtures
within the app and run command python manage.py loaddata <name_of_file>
will load all of this data to the specified model[
{
"model": "app_name.person",
"fileds": {
"rank": 1,
"employer": "Walmart",
"employeesCount": 2300000,
"medianSalary": 19177
}
},
{
"model": "app_name.person",
"fileds": {
"rank": 2,
"employer": "Amazon",
"employeesCount": 566000,
"medianSalary": 38466
}
}
]
I don't know if 2nd option is feasible for you but the first option would definitely work.
Upvotes: 1