summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/db/models/fields/__init__.py7
-rw-r--r--tests/model_fields/tests.py7
2 files changed, 12 insertions, 2 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index e6fa29a565..3215927ea0 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -2141,12 +2141,15 @@ class TextField(Field):
def get_internal_type(self):
return "TextField"
- def get_prep_value(self, value):
- value = super(TextField, self).get_prep_value(value)
+ def to_python(self, value):
if isinstance(value, six.string_types) or value is None:
return value
return smart_text(value)
+ def get_prep_value(self, value):
+ value = super(TextField, self).get_prep_value(value)
+ return self.to_python(value)
+
def formfield(self, **kwargs):
# Passing max_length to forms.CharField means that the value's length
# will be validated twice. This is considered acceptable since we want
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py
index 3e59f6465b..939ba269d8 100644
--- a/tests/model_fields/tests.py
+++ b/tests/model_fields/tests.py
@@ -246,6 +246,13 @@ class ManyToManyFieldTests(test.SimpleTestCase):
)
+class TextFieldTests(test.TestCase):
+ def test_to_python(self):
+ """TextField.to_python() should return a string"""
+ f = models.TextField()
+ self.assertEqual(f.to_python(1), '1')
+
+
class DateTimeFieldTests(test.TestCase):
def test_datetimefield_to_python_usecs(self):
"""DateTimeField.to_python should support usecs"""