P-115
This commit is contained in:
1 parent
1f4c97aa3d
commit
39fd61473c
1 file changed
+20
-2
+20
-2
@@ -88,20 +88,38 @@ class VoteCreate(APIView):
|
||||
)
|
||||
vote.save()
|
||||
|
||||
questions_files = request.FILES.getlist('questionsfiles')
|
||||
answers_files = request.FILES.getlist('answersfiles')
|
||||
|
||||
questions = json.loads(request.data['questions'])
|
||||
for count, question_data in enumerate(questions, start=1):
|
||||
|
||||
question_image = None
|
||||
if 'image' in question_data:
|
||||
for file in questions_files:
|
||||
if file.name == question_data['image']['name']:
|
||||
question_image = file
|
||||
break
|
||||
|
||||
question = Question(
|
||||
question=question_data['text'],
|
||||
vote=vote,
|
||||
file=question_data['image'],
|
||||
file=question_image,
|
||||
numb=count,
|
||||
settings=question_data.get('settings', {}),
|
||||
)
|
||||
question.save()
|
||||
|
||||
for answer in question_data['answers']:
|
||||
answer_image = None
|
||||
if 'image' in answer:
|
||||
for file in answers_files:
|
||||
if file.name == answer['image']['name']:
|
||||
answer_image = file
|
||||
break
|
||||
Answer(
|
||||
answer=answer['text'],
|
||||
file=answer['image'],
|
||||
file=answer_image,
|
||||
question=question
|
||||
).save()
|
||||
|
||||
|
||||
Reference in new issue
Block a user