Created
August 3, 2020 04:27
-
-
Save MainaKamau92/7f258c34d67a93289cdb1f59283a8f17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import viewsets, status | |
from rest_framework.exceptions import ValidationError | |
from rest_framework.permissions import AllowAny | |
from rest_framework.response import Response | |
from pollsapi.tenant.models import Client | |
from pollsapi.tenant.serializers import ClientSerializer | |
class ClientViewSet(viewsets.ViewSet): | |
permission_classes = (AllowAny,) | |
serializer_class = ClientSerializer | |
def create(self, request): | |
client = request.data or {} | |
tenant_name = client.get('tenant_name') | |
if tenant_name is None: | |
raise ValidationError('A tenant name is mandatory.') | |
tenant = Client.objects.get(tenant_name=tenant_name) | |
serializer = self.serializer_class(tenant, many=False) | |
return Response(serializer.data, status=status.HTTP_200_OK) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment