serializers.py 1.25 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
26
    full_name = serializers.ReadOnlyField(source='contact.full_name')
    first_name = serializers.ReadOnlyField(source='contact.first_name')
    last_name = serializers.ReadOnlyField(source='contact.last_name')
    phone = serializers.ReadOnlyField(source='contact.phone')
27
    groups = GroupSerializer(many=True, source='contact.groups')
28
29
    contact_id = serializers.ReadOnlyField(source='contact.id')
    photo = serializers.ReadOnlyField(source='contact.get_photo_url')
Aymeric Barantal's avatar
Aymeric Barantal committed
30
31
32

    class Meta:
        model = CampaignContact
33
        fields = ('id', 'weight', 'contact_id',
34
                  'full_name', 'first_name', 'last_name', 'phone', 'groups', 'photo')