изменения в GetResults
This commit is contained in:
1 parent
fc5a8e464d
commit
210fa319d1
1 file changed
+8
-4
@@ -167,11 +167,14 @@ class GetResults(APIView):
|
||||
answers_employee = Answer.objects.filter(
|
||||
question__vote=vote,
|
||||
question__settings__choice="employee"
|
||||
).values_list('name', flat=True)
|
||||
).values('name', 'question')
|
||||
|
||||
answers_names = [item['name'] for item in answers_employee]
|
||||
question_ids = [item['question'] for item in answers_employee]
|
||||
|
||||
employee_dict = {}
|
||||
if answers_employee:
|
||||
employees = DictEmployee.objects.filter(id__in=answers_employee)
|
||||
employees = DictEmployee.objects.filter(id__in=answers_names)
|
||||
employee_dict = {employee['id']: employee for employee in DictEmployeeSerializer(employees, many=True).data}
|
||||
|
||||
results = Result.objects.filter(
|
||||
@@ -183,8 +186,9 @@ class GetResults(APIView):
|
||||
for question in serialized_data['questions']:
|
||||
for answer in question['answers']:
|
||||
answer['count'] = result_dict.get(int(answer['id']), 0)
|
||||
if answer['name'] in answers_employee:
|
||||
answer['employee'] = employee_dict.get(int(answer['name']))
|
||||
if question['id'] in question_ids:
|
||||
if answer['name'] in answers_names:
|
||||
answer['employee'] = employee_dict.get(int(answer['name']))
|
||||
|
||||
return Response(serialized_data)
|
||||
|
||||
|
||||
Reference in new issue
Block a user