Commit d3c33e90 authored by Aymeric Barantal's avatar Aymeric Barantal

add POST for feedback, not proper code but work a minima

parent bf440a26
from picampaign.feedback.models import Feedback
from rest_framework import serializers
class FeedbackSerializer(serializers.ModelSerializer):
class Meta:
model = Feedback
fields = ('comment', 'callee')
from django.shortcuts import render
from rest_framework import viewsets
from rest_framework.response import Response
# Create your views here.
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
feedback = Feedback(**serializer.data)
feedback.save()
return Response(feedback.id)
......@@ -4,6 +4,7 @@ from rest_framework_nested import routers
from picampaign.campaign.views import (CampaignViewSet, CampaignContactViewSet,
ArgumentaryViewSet)
from picampaign.feedback.views import FeedbackViewSet
router = routers.SimpleRouter()
router.register(r'campaigns', CampaignViewSet)
......@@ -12,6 +13,7 @@ campaign_router = routers.NestedSimpleRouter(router, r'campaigns',
lookup='campaign')
campaign_router.register(r'contacts', CampaignContactViewSet)
campaign_router.register(r'arguments', ArgumentaryViewSet)
campaign_router.register(r'feedbacks', FeedbackViewSet)
urlpatterns = patterns('',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment