возврат изображений с голосованиями
This commit is contained in:
1 parent
bebfd39bd2
commit
1c4266ce8f
2 files changed
+22
-8
No files matched your search
+10
-8
@@ -9,6 +9,7 @@ from datetime import datetime
|
||||
from rest_framework import generics
|
||||
from navigation.models import News
|
||||
import json
|
||||
from collections import defaultdict
|
||||
|
||||
class GetVotes(APIView):
|
||||
|
||||
@@ -19,18 +20,19 @@ class GetVotes(APIView):
|
||||
now = datetime.now()
|
||||
status = request.query_params.get('status')
|
||||
votes = self.get_votes_by_status(status, now)
|
||||
serialized_votes = VoteSerializer(votes, many=True).data
|
||||
|
||||
serialized_votes = VotesSerializer(votes, many=True).data
|
||||
questions = Question.objects.filter(vote__in=votes)
|
||||
files = [question.file.url for question in questions if question.file]
|
||||
|
||||
questions_by_vote_id = defaultdict(list)
|
||||
for question in questions:
|
||||
questions_by_vote_id[question.vote.id].append(question)
|
||||
|
||||
for vote in serialized_votes:
|
||||
vote['is_passed'] = self.has_participated(user, vote['id'])
|
||||
related_questions = questions_by_vote_id[vote['id']]
|
||||
vote['files'] = [question.file.url for question in related_questions if question.file]
|
||||
|
||||
result = {
|
||||
'votes': serialized_votes,
|
||||
'files': files}
|
||||
|
||||
return Response(result)
|
||||
return Response(serialized_votes)
|
||||
|
||||
def get_votes_by_status(self, status, now):
|
||||
print(status)
|
||||
|
||||
Reference in new issue
Block a user