def patch(self, request):
     profile = Profile.objects.get(user=request.user)
     serializer = ProfileSerializer(profile, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_200_OK)
     return Response(serializer.errors,
                     status=status.HTTP_406_NOT_ACCEPTABLE)
def register(request):
    form = RegisterForm(request.POST)
    if form.is_valid():
        user = form.save(commit=False)
        user.save()
        profile = Profile.objects.get_or_create(user=user)
        serializer = ProfileSerializer(profile, data=request.data)
        if serializer.is_valid():
            serializer.save()
        return Response(status=status.HTTP_201_CREATED)
    return Response(form.errors, status=status.HTTP_406_NOT_ACCEPTABLE)
def register(request):  # fix here
    """
        registeration
        ---
        # Parameters
            - username: string
            - email: string | email-format
            - password1: string | password
            - password2: string | password confirmation
            - name: string | the user's name
            - weight: float
            - average_sleep_time : float
            - sleep_at: string | time format | nullable
            - image: string | image url | nullable
    """
    form = RegisterForm(request.POST)
    if form.is_valid():
        user = form.save(commit=False)
        try:  # fix it later
            user.save()
        except:
            pass
        profile = Profile.objects.create(
            user=user,
            name='default',
            weight=-1,
            average_sleep_time=-1,
        )
        serializer = ProfileSerializer(profile, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(status=status.HTTP_201_CREATED)
        Profile.objects.get(user=user).delete()
        #import pdb; pdb.set_trace()
        print(serializer.errors)
        return Response(serializer.errors,
                        status=status.HTTP_406_NOT_ACCEPTABLE)
    print("form not valid")
    print(form.errors)
    return Response(form.errors, status=status.HTTP_406_NOT_ACCEPTABLE)