Commit 3f60b63e authored by Aymeric Barantal's avatar Aymeric Barantal

filter feedback categories based on campaign related organization

parent 9aa06bbc
...@@ -14,7 +14,7 @@ class Campaign(models.Model): ...@@ -14,7 +14,7 @@ class Campaign(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
description = models.CharField(max_length=512, blank=True) description = models.CharField(max_length=512, blank=True)
organization = models.ForeignKey(Organization) organization = models.ForeignKey(Organization, related_name='campaigns')
start_date = models.DateField() start_date = models.DateField()
end_date = models.DateField() end_date = models.DateField()
default_lang = models.CharField(max_length=5, default_lang = models.CharField(max_length=5,
......
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework.response import Response from rest_framework.response import Response
from picampaign.organization.models import FeedbackCategory from picampaign.organization.models import FeedbackCategory, Organization
from picampaign.organization.serializers import CategorySerializer from picampaign.organization.serializers import CategorySerializer
...@@ -10,8 +10,8 @@ class CategoryViewSet(viewsets.ViewSet): ...@@ -10,8 +10,8 @@ class CategoryViewSet(viewsets.ViewSet):
queryset = FeedbackCategory.objects.all() queryset = FeedbackCategory.objects.all()
serializer_class = CategorySerializer serializer_class = CategorySerializer
def list(self, request, campaign_pk=None): def list(self, request, campaign_pk):
# XXX need an organization in request to filter upon orga = Organization.objects.filter(campaigns__id=campaign_pk)[0]
categories = self.queryset.all() categories = self.queryset.filter(organization_id=orga.id)
serializer = self.serializer_class(categories, many=True) serializer = self.serializer_class(categories, many=True)
return Response(serializer.data) return Response(serializer.data)
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