изменения в VoteResultCreate
This commit is contained in:
1 parent
10a9dc2910
commit
0cc1365f5d
1 file changed
+8
-12
+8
-12
@@ -202,19 +202,15 @@ class GetResults(APIView):
|
|||||||
|
|
||||||
return Response(serialized_data)
|
return Response(serialized_data)
|
||||||
|
|
||||||
from rest_framework.views import exception_handler
|
class VoteResultCreate(generics.ListCreateAPIView):
|
||||||
class VoteResultCreate(APIView):
|
queryset = Result.objects.all()
|
||||||
|
serializer_class = ResultSerializer
|
||||||
|
|
||||||
def post(self, request):
|
def create(self, request, *args, **kwargs):
|
||||||
user_id = request.user.id
|
serializer = self.get_serializer(data=request.data, many=True)
|
||||||
answer_ids = [item['answer'] for item in request.data]
|
if serializer.is_valid():
|
||||||
answers = Answer.objects.in_bulk(answer_ids)
|
serializer.save()
|
||||||
vote = list(answers.values())[0].question.vote
|
return Response(serializer.data)
|
||||||
results = Result.objects.bulk_create(
|
|
||||||
[Result(answer=answers[answer_id], user_id=user_id) for answer_id in answer_ids]
|
|
||||||
)
|
|
||||||
serializer = ResultSerializer(results, many=True)
|
|
||||||
return Response(serializer.data)
|
|
||||||
|
|
||||||
def get_employees_serializer(ids):
|
def get_employees_serializer(ids):
|
||||||
employees = DictEmployee.objects.filter(id__in=ids)
|
employees = DictEmployee.objects.filter(id__in=ids)
|
||||||
|
|||||||
Reference in new issue
Block a user