-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathviews.py
43 lines (27 loc) · 1.31 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from rest_framework import generics, status
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from project.organisations.models import Organisation, Membership
from project.organisations.serializers import (
CreateOrganisationSerializer, OrganisationMembersSerializer,
RetrieveOrganisationSerializer, OrganisationDetailSerializer
)
class RetrieveOrganisationView(generics.RetrieveAPIView):
serializer_class = RetrieveOrganisationSerializer
class CreateOrganisationView(generics.CreateAPIView):
serializer_class = CreateOrganisationSerializer
class OrganisationMembersView(generics.ListAPIView):
serializer_class = OrganisationMembersSerializer
def get_queryset(self):
organisation = Organisation.objects.order_by('?').first()
return Membership.objects.filter(organisation=organisation)
class LeaveOrganisationView(generics.DestroyAPIView):
def get_object(self):
return Membership.objects.order_by('?').first()
def delete(self, request, *args, **kwargs):
instance = self.get_object()
self.perform_destroy(instance)
return Response(status=status.HTTP_204_NO_CONTENT)
class OrganisationViewSet(ModelViewSet):
queryset = Organisation.objects.all()
serializer_class = OrganisationDetailSerializer