|
@@ -29,7 +29,9 @@ from django.utils.datastructures import DictWrapper
|
|
|
from django.utils.dateparse import (
|
|
|
parse_date, parse_datetime, parse_duration, parse_time,
|
|
|
)
|
|
|
-from django.utils.deprecation import RemovedInDjango20Warning
|
|
|
+from django.utils.deprecation import (
|
|
|
+ RemovedInDjango20Warning, warn_about_renamed_method,
|
|
|
+)
|
|
|
from django.utils.duration import duration_string
|
|
|
from django.utils.encoding import (
|
|
|
force_bytes, force_text, python_2_unicode_compatible, smart_text,
|
|
@@ -832,6 +834,10 @@ class Field(RegisterLookupMixin):
|
|
|
first_choice = blank_choice if include_blank else []
|
|
|
return first_choice + list(self.flatchoices)
|
|
|
|
|
|
+ @warn_about_renamed_method(
|
|
|
+ 'Field', '_get_val_from_obj', 'value_from_object',
|
|
|
+ RemovedInDjango20Warning
|
|
|
+ )
|
|
|
def _get_val_from_obj(self, obj):
|
|
|
if obj is not None:
|
|
|
return getattr(obj, self.attname)
|
|
@@ -843,7 +849,7 @@ class Field(RegisterLookupMixin):
|
|
|
Returns a string value of this field from the passed obj.
|
|
|
This is used by the serialization framework.
|
|
|
"""
|
|
|
- return smart_text(self._get_val_from_obj(obj))
|
|
|
+ return smart_text(self.value_from_object(obj))
|
|
|
|
|
|
def _get_flatchoices(self):
|
|
|
"""Flattened version of choices tuple."""
|
|
@@ -1298,7 +1304,7 @@ class DateField(DateTimeCheckMixin, Field):
|
|
|
return connection.ops.adapt_datefield_value(value)
|
|
|
|
|
|
def value_to_string(self, obj):
|
|
|
- val = self._get_val_from_obj(obj)
|
|
|
+ val = self.value_from_object(obj)
|
|
|
return '' if val is None else val.isoformat()
|
|
|
|
|
|
def formfield(self, **kwargs):
|
|
@@ -1458,7 +1464,7 @@ class DateTimeField(DateField):
|
|
|
return connection.ops.adapt_datetimefield_value(value)
|
|
|
|
|
|
def value_to_string(self, obj):
|
|
|
- val = self._get_val_from_obj(obj)
|
|
|
+ val = self.value_from_object(obj)
|
|
|
return '' if val is None else val.isoformat()
|
|
|
|
|
|
def formfield(self, **kwargs):
|
|
@@ -1680,7 +1686,7 @@ class DurationField(Field):
|
|
|
return converters + super(DurationField, self).get_db_converters(connection)
|
|
|
|
|
|
def value_to_string(self, obj):
|
|
|
- val = self._get_val_from_obj(obj)
|
|
|
+ val = self.value_from_object(obj)
|
|
|
return '' if val is None else duration_string(val)
|
|
|
|
|
|
def formfield(self, **kwargs):
|
|
@@ -2288,7 +2294,7 @@ class TimeField(DateTimeCheckMixin, Field):
|
|
|
return connection.ops.adapt_timefield_value(value)
|
|
|
|
|
|
def value_to_string(self, obj):
|
|
|
- val = self._get_val_from_obj(obj)
|
|
|
+ val = self.value_from_object(obj)
|
|
|
return '' if val is None else val.isoformat()
|
|
|
|
|
|
def formfield(self, **kwargs):
|
|
@@ -2355,7 +2361,7 @@ class BinaryField(Field):
|
|
|
|
|
|
def value_to_string(self, obj):
|
|
|
"""Binary data is serialized as base64"""
|
|
|
- return b64encode(force_bytes(self._get_val_from_obj(obj))).decode('ascii')
|
|
|
+ return b64encode(force_bytes(self.value_from_object(obj))).decode('ascii')
|
|
|
|
|
|
def to_python(self, value):
|
|
|
# If it's a string, it should be base64-encoded data
|