diff --git a/django/db/models/base.py b/django/db/models/base.py
index 31310ea..f1632f2 100644
a
|
b
|
from django.db import (connections, router, transaction, DatabaseError,
|
19 | 19 | from django.db.models import signals |
20 | 20 | from django.db.models.loading import register_models, get_model |
21 | 21 | from django.utils.translation import ugettext_lazy as _ |
22 | | from django.utils.functional import curry |
| 22 | from django.utils.functional import curry, Promise |
23 | 23 | from django.utils.encoding import smart_str, force_unicode |
24 | 24 | from django.utils.text import get_text_list, capfirst |
25 | 25 | from django.conf import settings |
… |
… |
class Model(object):
|
297 | 297 | # is *not* consumed. We rely on this, so don't change the order |
298 | 298 | # without changing the logic. |
299 | 299 | for val, field in izip(args, fields_iter): |
| 300 | if isinstance(val, Promise): |
| 301 | val = force_unicode(val) |
300 | 302 | setattr(self, field.attname, val) |
301 | 303 | else: |
302 | 304 | # Slower, kwargs-ready version. |
303 | 305 | for val, field in izip(args, fields_iter): |
| 306 | if isinstance(val, Promise): |
| 307 | val = force_unicode(val) |
304 | 308 | setattr(self, field.attname, val) |
305 | 309 | kwargs.pop(field.name, None) |
306 | 310 | # Maintain compatibility with existing calls. |
… |
… |
class Model(object):
|
354 | 358 | # checked) by the RelatedObjectDescriptor. |
355 | 359 | setattr(self, field.name, rel_obj) |
356 | 360 | else: |
| 361 | if isinstance(val, Promise): |
| 362 | val = force_unicode(val) |
357 | 363 | setattr(self, field.attname, val) |
358 | 364 | |
359 | 365 | if kwargs: |
diff --git a/tests/modeltests/many_to_one/tests.py b/tests/modeltests/many_to_one/tests.py
index 8a2af21..cb31c75 100644
a
|
b
|
from datetime import datetime
|
3 | 3 | |
4 | 4 | from django.test import TestCase |
5 | 5 | from django.core.exceptions import FieldError |
| 6 | from django.utils.translation import ugettext_lazy |
6 | 7 | |
7 | 8 | from models import Article, Reporter |
8 | 9 | |
… |
… |
class ManyToOneTests(TestCase):
|
372 | 373 | # recursive don't cause recursion depth problems under deepcopy. |
373 | 374 | self.r.cached_query = Article.objects.filter(reporter=self.r) |
374 | 375 | self.assertEqual(repr(deepcopy(self.r)), "<Reporter: John Smith>") |
| 376 | |
| 377 | def test_create_relation_with_ugettext_lazy(self): |
| 378 | reporter = Reporter.objects.create(first_name='John', |
| 379 | last_name='Smith', |
| 380 | email='john.smith@example.com') |
| 381 | lazy = ugettext_lazy(u'test') |
| 382 | reporter.article_set.create(headline=lazy, |
| 383 | pub_date=datetime(2011, 6, 10)) |
| 384 | notlazy = unicode(lazy) |
| 385 | article = reporter.article_set.get() |
| 386 | self.assertEqual(article.headline, notlazy) |