diff --git a/src/back/vote/views.py b/src/back/vote/views.py index b859221a7..8c9388b63 100644 --- a/src/back/vote/views.py +++ b/src/back/vote/views.py @@ -48,8 +48,9 @@ class VoteDetail(generics.RetrieveUpdateDestroyAPIView): lookup_url_kwarg = 'id' lookup_field = 'id' -class VoteCreate(APIView): +import json +class VoteCreate(APIView): def post(self, request): user = request.user user = DictEmployee.objects.get(login='9966-00-125') @@ -63,17 +64,21 @@ class VoteCreate(APIView): author=user, ) vote.save() - - for count, question_data in enumerate(request.data['questions'], start=1): + + questions = json.loads(request.data['questions']) + for count, question_data in enumerate(questions, start=1): question = Question( question=question_data['text'], vote=vote, - # file=question.get('image', None), - file = request.FILES.get('image'), + file=request.FILES.get('image'), numb=count, ) question.save() for answer in question_data['answers']: - Answer(answer=answer['text'], file=request.FILES.get('image'), question=question).save() - - return Response({'status': 'success', 'message': 'Vote created successfully.'}, status=201) \ No newline at end of file + Answer( + answer=answer['text'], + file=request.FILES.get('image'), + question=question + ).save() + + return Response({'status': 'success', 'message': 'Vote created successfully.'}, status=201) diff --git a/src/front/src/components/vote/VoteConstructor.vue b/src/front/src/components/vote/VoteConstructor.vue index 1cd2261a4..2aae8177e 100644 --- a/src/front/src/components/vote/VoteConstructor.vue +++ b/src/front/src/components/vote/VoteConstructor.vue @@ -249,7 +249,7 @@