cmsmanage/membershipworks/api.py

31 lines
757 B
Python

from rest_framework import routers, serializers, viewsets
from .models import Flag, Member
class MemberSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Member
fields = "__all__"
class MemberViewSet(viewsets.ModelViewSet):
queryset = Member.objects.prefetch_related("flags")
serializer_class = MemberSerializer
class FlagSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Flag
fields = "__all__"
class FlagViewSet(viewsets.ModelViewSet):
queryset = Flag.objects.all()
serializer_class = FlagSerializer
router = routers.DefaultRouter()
router.register(r"membershipworks/member", MemberViewSet)
router.register(r"membershipworks/flag", FlagViewSet)