serializers.py 1.06 KB
Newer Older
1
from picampaign.campaign.models import (Campaign, CampaignContact,
2
                                        Argumentary)
3
from picampaign.organization.serializers import GroupSerializer
Aymeric Barantal's avatar
Aymeric Barantal committed
4 5 6
from rest_framework import serializers


7 8 9 10 11 12 13
class ArgumentarySerializer(serializers.ModelSerializer):

    class Meta:
        model = Argumentary
        fields = ('lang', 'text')


Aymeric Barantal's avatar
Aymeric Barantal committed
14 15 16 17 18 19 20 21 22
class CampaignSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:
        model = Campaign
        fields = ('id', 'title', 'description', 'start_date', 'end_date')


class CampaignContactSerializer(serializers.HyperlinkedModelSerializer):

23 24 25
    first_name = serializers.Field(source='contact.first_name')
    last_name = serializers.Field(source='contact.last_name')
    phone = serializers.Field(source='contact.phone')
26
    groups = GroupSerializer(many=True, source='contact.groups')
27
    contact_id = serializers.Field(source='contact.id')
Aymeric Barantal's avatar
Aymeric Barantal committed
28 29 30

    class Meta:
        model = CampaignContact
31 32
        fields = ('id', 'weight', 'contact_id',
                  'first_name', 'last_name', 'phone', 'groups')