Skip to content
Prev Previous commit
Next Next commit
Use new value_from_object in preference to internal _get_val_from_obj
  • Loading branch information
lovelydinosaur committed Jun 2, 2016
commit b6a7c527a8528e5bd42036825d0303ae73bf4f92
6 changes: 6 additions & 0 deletions rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def get_related_model(field):
return field.remote_field.model


def value_from_object(field, obj):
if django.VERSION < (1, 9):
return field._get_val_from_obj(obj)
field.value_from_object(obj)


# contrib.postgres only supported from 1.8 onwards.
try:
from django.contrib.postgres import fields as postgres_fields
Expand Down
4 changes: 2 additions & 2 deletions rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from rest_framework import ISO_8601
from rest_framework.compat import (
get_remote_field, unicode_repr, unicode_to_repr
get_remote_field, unicode_repr, unicode_to_repr, value_from_object
)
from rest_framework.exceptions import ValidationError
from rest_framework.settings import api_settings
Expand Down Expand Up @@ -1687,7 +1687,7 @@ def get_attribute(self, obj):
return obj

def to_representation(self, obj):
value = self.model_field._get_val_from_obj(obj)
value = value_from_object(self.model_field, obj)
if is_protected_type(value):
return value
return self.model_field.value_to_string(obj)