import os
import django
import json
import random

os.environ.setdefault('DJANGO_SETTINGS_MODULE','QuestionsBidding.settings')
# # settings.configure()
django.setup()
from bidding.models import Question

fields=['question', 'a', 'b', 'c', 'd', 'answer']

for row in json.load(open('questions.json'))['results']:
	row['incorrect_answers'].append(row['correct_answer'])
	random.shuffle(row['incorrect_answers'])
	data = [ row['question'] ]
	data.extend(row['incorrect_answers'])
	data.append([ 'a', 'b', 'c', 'd' ][ row['incorrect_answers'].index(row['correct_answer']) ])
	Question.objects.create(**dict(zip(fields, data)))