views.py 832 Bytes
Newer Older
1
2
from rest_framework import viewsets
from rest_framework.response import Response
Aymeric Barantal's avatar
Aymeric Barantal committed
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from picampaign.feedback.serializers import FeedbackSerializer
from picampaign.feedback.models import Feedback, FeedbackCategory
from picampaign.campaign.models import CampaignContact


class FeedbackViewSet(viewsets.ViewSet):

    queryset = Feedback.objects.all()
    serializer_class = FeedbackSerializer

    def create(self, request, campaign_pk=None):
        serializer = FeedbackSerializer(request.DATA)
        callee = CampaignContact.objects.get(id=request.DATA['callee'])
        category = FeedbackCategory.objects.get(id=request.DATA['category'])
        serializer.data['callee'] = callee
        serializer.data['category'] = category
20
        feedback = Feedback.objects.create(**serializer.data)
21
        return Response(feedback.id)