mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 04:20:12 +03:00
Extract modern code from value_from_object() in compat.py and remove
This commit is contained in:
parent
7b6180a5c8
commit
de202e4acd
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user