Skip to content

Instantly share code, notes, and snippets.

@aballah-chamakh
Created July 11, 2019 12:55
Show Gist options
  • Select an option

  • Save aballah-chamakh/de769fef7330a2d2ad7958bee305b03e to your computer and use it in GitHub Desktop.

Select an option

Save aballah-chamakh/de769fef7330a2d2ad7958bee305b03e to your computer and use it in GitHub Desktop.
from django.shortcuts import render
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework import viewsets,status,generics
from .models import User,Profile
from .serializers import SimpleProfileSerializer,ProfileSerializer
from .UserSerializer import UserSerializer
from .permissions import IsOwnerAndAuthenticated
class UserViewSet(viewsets.ModelViewSet):
serializer_class = UserSerializer
queryset = User.objects.all()
permissons_classes = (IsOwnerAndAuthenticated,)
@action(methods=['GET'],detail=False)
def email_exist(self,request):
email = request.data.get('email')
qs = User.objects.filter(email=email)
if qs :
return Response({'exist':True},status=status.HTTP_200_OK)
else :
return Response({'exist':False},status=status.HTTP_200_OK)
class ProfileViewSet(viewsets.ModelViewSet):
serializer_class = ProfileSerializer
queryset = Profile.objects.all()
permissons_classes = (IsOwnerAndAuthenticated,)
lookup_field = 'slug'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment