Доработаны роуты для голосования и получения информации о голосованиях
This commit is contained in:
1 parent
dfc412dfc8
commit
5c9368f666
4 files changed
+35
-13
No files matched your search
+27
-5
@@ -1,13 +1,35 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from .models import *
|
||||
from .serializers import *
|
||||
|
||||
# Create your views here.
|
||||
|
||||
class SetThanks(APIView):
|
||||
def post(self, request):
|
||||
cand_thanks_id = request.GET.get('id')
|
||||
ThanksVote.objects.update_or_create(
|
||||
cand_name_id = cand_thanks_id,
|
||||
defaults = None
|
||||
)
|
||||
return Response("Ваш голос добавлен!")
|
||||
|
||||
class GetThanks(APIView):
|
||||
|
||||
def get(self, request):
|
||||
cand_id = request.GET.get('id')
|
||||
req_cand = ThanksVote.objects.filter(cand_name_id = cand_id, thanks = True)
|
||||
print(f'candidate_id: {req_cand}')
|
||||
return Response('test')
|
||||
all_thanks = ThanksVote.objects.all()
|
||||
return Response(ThanksVoteSerializer(all_thanks, many=True).data)
|
||||
|
||||
|
||||
class SetBest(APIView):
|
||||
def post(self, request):
|
||||
cand_best_id = request.GET.get('id')
|
||||
BestVote.objects.update_or_create(
|
||||
cand_name_id = cand_best_id,
|
||||
defaults = None
|
||||
)
|
||||
return Response("Ваш голос добавлен!")
|
||||
|
||||
class GetBest(APIView):
|
||||
def get(self, request):
|
||||
all_thanks = BestVote.objects.all()
|
||||
return Response(BestVoteSerializer(all_thanks, many=True).data)
|
||||
Reference in new issue
Block a user