def to_internal_value(self, data):
    if (self.serializer_field is not None):
        data = self.serializer_field.to_internal_value(data)
    try:
        return self.get_queryset().get(**{self.related_field_name: data})
    except ObjectDoesNotExist:
        self.fail('does_not_exist', pk_value=data)
    except (TypeError, ValueError):
        self.fail('incorrect_type', data_type=type(data).__name__)
def to_internal_value(self, data):
    if (self.serializer_field is not None):
        data = self.serializer_field.to_internal_value(data)
    try:
        return self.get_queryset().get(**{self.related_field_name: data})
    except ObjectDoesNotExist:
        self.fail('does_not_exist', pk_value=data)
    except (TypeError, ValueError):
        self.fail('incorrect_type', data_type=type(data).__name__)