summaryrefslogtreecommitdiff
path: root/django/db/models
diff options
context:
space:
mode:
authorThomas Stephenson <ovangle@gmail.com>2015-04-26 16:30:46 +1000
committerTim Graham <timograham@gmail.com>2015-07-14 09:13:22 -0400
commit035b0fa60da2e758d0ab7f9d04ef93cdb73c981f (patch)
tree4effeaa7efc8c9ac62bd32817daa3c5da750b7bf /django/db/models
parent0ffa3943fbd100e7de7b1ddbfd301ddc52b57410 (diff)
Fixed #24716 -- Deprecated Field._get_val_from_obj()
The method duplicates the functionality of Field.value_from_object() and has the additional downside of being a privately named public API method.
Diffstat (limited to 'django/db/models')
-rw-r--r--django/db/models/fields/__init__.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 5ae1aa3dc7..2c9ab104cc 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -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