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


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

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


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

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

21
22
23
24
25
class PhoneSerializer(serializers.ModelSerializer):

    class Meta:
        model = Phone
        fields = ('id', 'phone', 'valid')
Aymeric Barantal's avatar
Aymeric Barantal committed
26
27
28

class CampaignContactSerializer(serializers.HyperlinkedModelSerializer):

29
30
31
    full_name = serializers.ReadOnlyField(source='contact.full_name')
    first_name = serializers.ReadOnlyField(source='contact.first_name')
    last_name = serializers.ReadOnlyField(source='contact.last_name')
32
    phones = PhoneSerializer(many=True, source='contact.phones')
33
    groups = GroupSerializer(many=True, source='contact.groups')
34
35
    contact_id = serializers.ReadOnlyField(source='contact.id')
    photo = serializers.ReadOnlyField(source='contact.get_photo_url')
Aymeric Barantal's avatar
Aymeric Barantal committed
36
37
38

    class Meta:
        model = CampaignContact
39
        fields = ('id', 'weight', 'contact_id',
40
                  'full_name', 'first_name', 'last_name', 'phones', 'groups', 'photo')