Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
piphone
campaign
Commits
3f60b63e
Commit
3f60b63e
authored
Nov 22, 2014
by
Aymeric Barantal
Browse files
filter feedback categories based on campaign related organization
parent
9aa06bbc
Changes
2
Hide whitespace changes
Inline
Side-by-side
picampaign/campaign/models.py
View file @
3f60b63e
...
...
@@ -14,7 +14,7 @@ class Campaign(models.Model):
id
=
models
.
AutoField
(
primary_key
=
True
)
title
=
models
.
CharField
(
max_length
=
255
)
description
=
models
.
CharField
(
max_length
=
512
,
blank
=
True
)
organization
=
models
.
ForeignKey
(
Organization
)
organization
=
models
.
ForeignKey
(
Organization
,
related_name
=
'campaigns'
)
start_date
=
models
.
DateField
()
end_date
=
models
.
DateField
()
default_lang
=
models
.
CharField
(
max_length
=
5
,
...
...
picampaign/organization/views.py
View file @
3f60b63e
from
rest_framework
import
viewsets
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
...
...
@@ -10,8 +10,8 @@ class CategoryViewSet(viewsets.ViewSet):
queryset
=
FeedbackCategory
.
objects
.
all
()
serializer_class
=
CategorySerializer
def
list
(
self
,
request
,
campaign_pk
=
None
):
# XXX need an organization in request to filter upon
categories
=
self
.
queryset
.
all
(
)
def
list
(
self
,
request
,
campaign_pk
):
orga
=
Organization
.
objects
.
filter
(
campaigns__id
=
campaign_pk
)[
0
]
categories
=
self
.
queryset
.
filter
(
organization_id
=
orga
.
id
)
serializer
=
self
.
serializer_class
(
categories
,
many
=
True
)
return
Response
(
serializer
.
data
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment