Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #5641 -- Handle lazy translations correctly when used as defaul…

…t arguments. Thanks, permon.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6453 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 185848a526f94cadf06060410dec0f8260c110f9 1 parent 4d8561a
@malcolmt malcolmt authored
View
2  django/db/models/fields/__init__.py
@@ -238,7 +238,7 @@ def get_default(self):
if self.default is not NOT_PROVIDED:
if callable(self.default):
return self.default()
- return self.default
+ return force_unicode(self.default, strings_only=True)
if not self.empty_strings_allowed or (self.null and settings.DATABASE_ENGINE != 'oracle'):
return None
return ""
View
2  tests/modeltests/basic/models.py
@@ -152,7 +152,7 @@ def __unicode__(self):
>>> a6 = Article(pub_date=datetime(2005, 7, 31))
>>> a6.save()
>>> a6.headline
-'Default headline'
+u'Default headline'
# For DateTimeFields, Django saves as much precision (in seconds) as you
# give it.
View
2  tests/modeltests/field_defaults/models.py
@@ -42,7 +42,7 @@ def __unicode__(self):
# Access database columns via Python attributes.
>>> a.headline
-'Default headline'
+u'Default headline'
# make sure the two dates are sufficiently close
>>> d = now - a.pub_date
View
12 tests/regressiontests/i18n/models.py
@@ -0,0 +1,12 @@
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+
+class TestModel(models.Model):
+ text = models.CharField(max_length=10, default=_('Anything'))
+
+__test__ = {'API_TESTS': '''
+>>> tm = TestModel()
+>>> tm.save()
+'''
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.