from django.conf.urls import url, include
from django.contrib.auth.models import User
from members.models import Member, Group, GroupType, GroupMembership, Functionary, FunctionaryType
from rest_framework import routers, serializers, viewsets

# Serializers define the API representation.
class MemberSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Member
        fields = ('full_name', 'full_preferred_name', 'given_names', 'preferred_name', 'surname', 'maiden_name',\
            'nickname', 'birth_date', 'student_id', 'gender', 'graduated', 'graduated_year', 'dead', 'mobile_phone', \
            'phone', 'street_address', 'postal_code', 'city', 'country', 'url', 'email', 'subscribed_to_modulen', \
            'allow_publish_info', 'username', 'crm_id')

class GroupSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Group

class GroupTypeSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = GroupType

class GroupMembershipSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = GroupMembership

class FunctionarySerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Functionary

class FunctionaryTypeSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = FunctionaryType


# ViewSets define the view behavior.
class MemberViewSet(viewsets.ModelViewSet):
    queryset = Member.objects.all()
    serializer_class = MemberSerializer

class GroupViewSet(viewsets.ModelViewSet):
    queryset = Group.objects.all()
    serializer_class = GroupSerializer

class GroupTypeViewSet(viewsets.ModelViewSet):
    queryset = GroupType.objects.all()
    serializer_class = GroupTypeSerializer

class GroupMembershipViewSet(viewsets.ModelViewSet):
    queryset = GroupMembership.objects.all()
    serializer_class = GroupMembershipSerializer

class FunctionaryViewSet(viewsets.ModelViewSet):
    queryset = Functionary.objects.all()
    serializer_class = FunctionarySerializer

class FunctionaryTypeViewSet(viewsets.ModelViewSet):
    queryset = FunctionaryType.objects.all()
    serializer_class = FunctionaryTypeSerializer

# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'members', MemberViewSet)
router.register(r'groups', GroupViewSet)
router.register(r'groupTypes', GroupTypeViewSet)
router.register(r'groupMembership', GroupMembershipViewSet)
router.register(r'functionaries', FunctionaryViewSet)
router.register(r'functionaryTypes', FunctionaryTypeViewSet)

# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
    url(r'^', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
]

@@ -79,16 +79,55 @@
 rt User%0A
+from django_countries import Countries%0A
 from mem
@@ -276,16 +276,305 @@
 ewsets%0A%0A
+%0Aclass SerializableCountryField(serializers.ChoiceField):%0A    def to_representation(self, value):%0A        if value in ('', None):%0A            return ''  # instead of %60value%60 as Country(u'') is not serializable%0A        return super(SerializableCountryField, self).to_representation(value)%0A%0A
 # Serial
@@ -666,32 +666,110 @@
 delSerializer):%0A
+    country = SerializableCountryField(allow_blank=True, choices=Countries())%0A
     class Meta:%0A
@@ -1768,16 +1768,17 @@
 yType%0A%0A%0A
+%0A
 # ViewSe

Fix CountryField not serializable error