Extract modern code from value_from_object() in compat.py and remove

This commit is contained in:
Levi Payne 2017-10-04 19:20:54 -04:00
parent 7b6180a5c8
commit de202e4acd
2 changed files with 2 additions and 8 deletions

View File

@ -115,12 +115,6 @@ def _resolve_model(obj):
raise ValueError("{0} is not a Django model".format(obj))
# TODO: Remove
def value_from_object(field, obj):
if django.VERSION < (1, 9):
return field._get_val_from_obj(obj)
return field.value_from_object(obj)
# TODO: Remove
# contrib.postgres only supported from 1.8 onwards.

View File

@ -33,7 +33,7 @@ from rest_framework import ISO_8601
from rest_framework.compat import (
InvalidTimeError, MaxLengthValidator, MaxValueValidator,
MinLengthValidator, MinValueValidator, get_remote_field, unicode_repr,
unicode_to_repr, value_from_object
unicode_to_repr
)
from rest_framework.exceptions import ErrorDetail, ValidationError
from rest_framework.settings import api_settings
@ -1840,7 +1840,7 @@ class ModelField(Field):
return obj
def to_representation(self, obj):
value = value_from_object(self.model_field, obj)
value = self.model_field.value_from_object(obj)
if is_protected_type(value):
return value
return self.model_field.value_to_string(obj)