How To Save A List Of Numbers To Django Model
I am pulling some data from an API and I want to store it in my Django model. The data is a baseball inning and then runs scored that inning and comes to me like this...
"innings":[
0:0
1:3
2:0
3:0
4:1
5:2
6:0
7:0
8:4
]
I access each individual value like...
for game in games:
first_inning = game['scoreboard']['score']['innings'][0]
second_inning = game['scoreboard']['score']['innings'][1]
etc...
But if I wanted to save all the data as it is and start the innings at 1 instead of 0, which type of field would I use and how would I do that? Would it be an ArrayField?
I really appreciate your help.
Answer
There are some ways depending on your problem.
you can store your data in
ArrayField
. butArrayField
is only spcific to PostgreSQL database.(more information here)you can convert your data to JSON and store it in JSONField(more information about JSONField is here).
My suggestion is solution number 2 because you are reading serialized data from API.
I hope it could help you.
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module