Jovian
⭐️
Sign In
In [1]:
from item_bank.models import QBody,QOption,CandidateExamResponse,StudentQuestionResponse
import json
In [2]:
aa = QBody.objects.filter(pk__in=[71,72,73,74,75])
data = {}
for i,j in enumerate(aa):
    data[i+1] = {"user_answer":[],"question_id":j.pk,
    "id":i+1,"question_body":j.body_text,
        "option": {m+1:{"id":k.pk, "option":k.option_text,"checked":k.media_content_flag} for m,k in enumerate(j.qbody_qotion.all()) }
        }
md_data = {"questions":data}
In [3]:
md_data
Out[3]:
{'questions': {1: {'id': 1,
   'option': {1: {'checked': False, 'id': 185, 'option': 'Scripting language'},
    2: {'checked': False, 'id': 186, 'option': 'df'},
    3: {'checked': False, 'id': 187, 'option': 'sdf'},
    4: {'checked': False, 'id': 188, 'option': 'fg'}},
   'question_body': 'What is Python?',
   'question_id': 71,
   'user_answer': []},
  2: {'id': 2,
   'option': {1: {'checked': False, 'id': 189, 'option': 'New Delhi'},
    2: {'checked': False, 'id': 190, 'option': 'Bfhgh'}},
   'question_body': 'The capital of India?',
   'question_id': 72,
   'user_answer': []},
  3: {'id': 3,
   'option': {1: {'checked': False, 'id': 191, 'option': 'Mumbai'},
    2: {'checked': False, 'id': 192, 'option': 'Delhi'},
    3: {'checked': False, 'id': 193, 'option': 'Kolkata'},
    4: {'checked': False, 'id': 194, 'option': 'fsdaaaaaa'}},
   'question_body': 'The capital of Maharastra?',
   'question_id': 73,
   'user_answer': []},
  4: {'id': 4,
   'option': {1: {'checked': False, 'id': 195, 'option': 'Patna'},
    2: {'checked': False, 'id': 196, 'option': 'Gaya'},
    3: {'checked': False, 'id': 197, 'option': 'Kolkata'},
    4: {'checked': False, 'id': 198, 'option': 'Bengal'}},
   'question_body': 'The capital of Bihar?',
   'question_id': 74,
   'user_answer': []},
  5: {'id': 5,
   'option': {1: {'checked': False, 'id': 199, 'option': 'Madurai'},
    2: {'checked': False, 'id': 200, 'option': 'Bangalore'},
    3: {'checked': False, 'id': 201, 'option': 'Jaipur'},
    4: {'checked': False, 'id': 202, 'option': 'sdffffffff'}},
   'question_body': 'The capital of Karnataka?',
   'question_id': 75,
   'user_answer': []}}}
In [ ]:
StudentQuestionResponse.objects.get()
In [ ]:
 
In [ ]:
 
In [ ]: