Last active
August 29, 2015 14:08
-
-
Save akatreyt/fde2cd93cb960749cad9 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
class ConnectionRequestSerializer(serializers.ModelSerializer): | |
from_data = CustomUserSerializer(source='from_user') | |
to_data = CustomUserSerializer(source='to_user') | |
class Meta: | |
model = ConnectionRequest | |
class request_connection(APIView): | |
serializer_class = ConnectionRequestSerializer | |
def post(self, request, *args, **kwargs): | |
from_user_id = request.user.id | |
to_user_id = request.DATA['to_user'] | |
serializer = ConnectionRequestSerializer(data = {"to_user" : to_user_id, "from_user" : from_user_id}) | |
if serializer.is_valid(): | |
serializer.save() | |
return Response(serializer.data) | |
else: | |
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | |
****Error***** | |
from_data: [This field is required.] | |
to_data: [This field is required.] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment