Frontend (React) gives me this type of json data:
{
"question": [{
"id": '0',
"title": 'Click to write the question text',
"choice": ['Click to write Choice 1', 'Click to write Choice 2', 'Click to write Choice 3'],
"answerType": 'singleAnswer',
"answerStyle": 'vertical',
},
{
"id": '1',
"title": 'Click to write the question text',
"choice": ['Click to write Choice 1', 'Click to write Choice 2', 'Click to write Choice 3'],
"answerType": 'singleAnswer',
"answerStyle": 'horizontal',
},
{
"id": '2',
"title": 'Click to write the question text',
"choice": ['Click to write Choice 1', 'Click to write Choice 2', 'Click to write Choice 3'],
"answerType": 'multipleAnswer',
"answerStyle": 'horizontal',
},
]
}
I need to save it in my SQLite database in Django.
- How do I save the
choice
field? - If I make the Question and Choice models separately, how do I save the json choice one by one in the choice table? How to get back this data in the frontend?
- How should I design my model? What should I need to write in my API view?