Skip to content
GitLab
Menu
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
2444d374
Commit
2444d374
authored
Nov 22, 2014
by
Aymeric Barantal
Browse files
flatten output for campaigns/<id>/contacts
parent
27371eea
Changes
3
Hide whitespace changes
Inline
Side-by-side
picampaign/campaign/models.py
View file @
2444d374
...
...
@@ -56,3 +56,6 @@ class CampaignContact(models.Model):
def
__unicode__
(
self
):
return
'Contact %s on %s'
%
(
self
.
contact
,
self
.
campaign
.
title
)
def
all_groups
(
self
):
return
[
x
.
name
for
x
in
self
.
contact
.
groups
.
all
()]
picampaign/campaign/serializers.py
View file @
2444d374
from
picampaign.campaign.models
import
(
Campaign
,
CampaignContact
,
Contact
,
from
picampaign.campaign.models
import
(
Campaign
,
CampaignContact
,
Argumentary
)
from
rest_framework
import
serializers
class
ContactSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Contact
fields
=
(
'id'
,
'first_name'
,
'last_name'
,
'phone'
)
class
ArgumentarySerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
...
...
@@ -26,8 +19,11 @@ class CampaignSerializer(serializers.HyperlinkedModelSerializer):
class
CampaignContactSerializer
(
serializers
.
HyperlinkedModelSerializer
):
contact
=
ContactSerializer
(
many
=
False
)
first_name
=
serializers
.
Field
(
source
=
'contact.first_name'
)
last_name
=
serializers
.
Field
(
source
=
'contact.last_name'
)
phone
=
serializers
.
Field
(
source
=
'contact.phone'
)
groups
=
serializers
.
Field
(
source
=
'all_groups'
)
class
Meta
:
model
=
CampaignContact
fields
=
(
'id'
,
'weight'
,
'
contact
'
)
fields
=
(
'id'
,
'weight'
,
'
first_name'
,
'last_name'
,
'phone'
,
'groups
'
)
picampaign/organization/models.py
View file @
2444d374
...
...
@@ -20,7 +20,8 @@ class Group(models.Model):
name
=
models
.
CharField
(
max_length
=
64
)
type
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
)
media
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
)
contacts
=
models
.
ManyToManyField
(
Contact
,
null
=
True
,
blank
=
True
)
contacts
=
models
.
ManyToManyField
(
Contact
,
null
=
True
,
blank
=
True
,
related_name
=
'groups'
)
def
__unicode__
(
self
):
return
self
.
name
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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