Commit 2444d374 authored by Aymeric Barantal's avatar Aymeric Barantal
Browse files

flatten output for campaigns/<id>/contacts

parent 27371eea
......@@ -56,3 +56,6 @@ class CampaignContact(models.Model):
def __unicode__(self):
return 'Contact %s on %s' % (, self.campaign.title)
def all_groups(self):
return [ for x in]
from picampaign.campaign.models import (Campaign, CampaignContact, Contact,
from picampaign.campaign.models import (Campaign, CampaignContact,
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='')
groups = serializers.Field(source='all_groups')
class Meta:
model = CampaignContact
fields = ('id', 'weight', 'contact')
fields = ('id', 'weight', 'first_name', 'last_name', 'phone', 'groups')
......@@ -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,
def __unicode__(self):
Supports Markdown
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