serializers.py 717 Bytes
Newer Older
1
2
from rest_framework import serializers

3
from activemembers.models import MemberGroup, MemberGroupMembership
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from members.models import Member


class NextCloudMemberSerializer(serializers.ModelSerializer):
    class Meta:
        model = Member
        fields = ('pk', 'username', 'first_name',
                  'last_name', 'is_superuser', 'email')


class NextCloudGroupSerializer(serializers.ModelSerializer):
    class Meta:
        model = MemberGroup
        fields = ('pk', 'name', 'members')

19
20
21
22
23
    members = serializers.SerializerMethodField()

    def get_members(self, obj):
        return (MemberGroupMembership.active_objects.filter(group=obj)
                .values_list('member__username', flat=True))