изменения в 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)
|
||||
|
||||
from rest_framework.views import exception_handler
|
||||
class VoteResultCreate(APIView):
|
||||
class VoteResultCreate(generics.ListCreateAPIView):
|
||||
queryset = Result.objects.all()
|
||||
serializer_class = ResultSerializer
|
||||
|
||||
def post(self, request):
|
||||
user_id = request.user.id
|
||||
answer_ids = [item['answer'] for item in request.data]
|
||||
answers = Answer.objects.in_bulk(answer_ids)
|
||||
vote = list(answers.values())[0].question.vote
|
||||
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 create(self, request, *args, **kwargs):
|
||||
serializer = self.get_serializer(data=request.data, many=True)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return Response(serializer.data)
|
||||
|
||||
def get_employees_serializer(ids):
|
||||
employees = DictEmployee.objects.filter(id__in=ids)
|
||||
|
||||
Reference in new issue
Block a user