serializers.py 1004 Bytes
Newer Older
1
from django.contrib.sites.shortcuts import get_current_site
2 3
from rest_framework import serializers

4 5
from picampaign.organization.models import FeedbackCategory, Group, GroupType, Organization

6 7 8 9 10 11

class CategorySerializer(serializers.ModelSerializer):

    class Meta:
        model = FeedbackCategory
        fields = ('id', 'name')
12 13 14


class GroupSerializer(serializers.ModelSerializer):
15
    type = serializers.ReadOnlyField(source='type.name')
16 17 18

    class Meta:
        model = Group
okhin's avatar
okhin committed
19
        fields = ('id', 'type', 'name', 'media')
okhin's avatar
okhin committed
20

okhin's avatar
okhin committed
21

okhin's avatar
okhin committed
22 23 24 25
class GroupTypeSerializer(serializers.ModelSerializer):
    class Meta:
        model = GroupType
        fields = ('id', 'name')
okhin's avatar
okhin committed
26 27 28


class OrganizationSerializer(serializers.ModelSerializer):
29
    logo = serializers.SerializerMethodField()
okhin's avatar
okhin committed
30 31 32
    class Meta:
        model = Organization
        fields = ('id', 'name', 'description', 'website', 'logo',)
33 34 35 36 37

    def get_logo(self, obj):
        if obj.logo:
            return get_current_site + obj.logo.url
        return None