Ticket #10498: 10498-2.diff

File 10498-2.diff, 2.8 KB (added by Claude Paroz, 13 years ago)

Updated to latest trunk (r17503)

  • django/db/models/base.py

    diff --git a/django/db/models/base.py b/django/db/models/base.py
    index ebd67be..edd7758 100644
    a b from django.db.models.options import Options  
    2020from django.db.models import signals
    2121from django.db.models.loading import register_models, get_model
    2222from django.utils.translation import ugettext_lazy as _
    23 from django.utils.functional import curry
     23from django.utils.functional import curry, Promise
    2424from django.utils.encoding import smart_str, force_unicode
    2525from django.utils.text import get_text_list, capfirst
    2626
    class Model(object):  
    298298            # is *not* consumed. We rely on this, so don't change the order
    299299            # without changing the logic.
    300300            for val, field in izip(args, fields_iter):
     301                if isinstance(val, Promise):
     302                    val = force_unicode(val)
    301303                setattr(self, field.attname, val)
    302304        else:
    303305            # Slower, kwargs-ready version.
    304306            for val, field in izip(args, fields_iter):
     307                if isinstance(val, Promise):
     308                    val = force_unicode(val)
    305309                setattr(self, field.attname, val)
    306310                kwargs.pop(field.name, None)
    307311                # Maintain compatibility with existing calls.
    class Model(object):  
    355359                # checked) by the RelatedObjectDescriptor.
    356360                setattr(self, field.name, rel_obj)
    357361            else:
     362                if isinstance(val, Promise):
     363                    val = force_unicode(val)
    358364                setattr(self, field.attname, val)
    359365
    360366        if kwargs:
  • tests/modeltests/many_to_one/tests.py

    diff --git a/tests/modeltests/many_to_one/tests.py b/tests/modeltests/many_to_one/tests.py
    index bc9fe64..d9d67bb 100644
    a b from datetime import datetime  
    55
    66from django.core.exceptions import MultipleObjectsReturned
    77from django.test import TestCase
     8from django.utils.translation import ugettext_lazy
    89
    910from .models import Article, Reporter
    1011
    class ManyToOneTests(TestCase):  
    412413
    413414        # Same as each other
    414415        self.assertTrue(r1.article_set.__class__ is r2.article_set.__class__)
     416
     417    def test_create_relation_with_ugettext_lazy(self):
     418        reporter = Reporter.objects.create(first_name='John',
     419                                           last_name='Smith',
     420                                           email='john.smith@example.com')
     421        lazy = ugettext_lazy(u'test')
     422        reporter.article_set.create(headline=lazy,
     423                                    pub_date=datetime(2011, 6, 10))
     424        notlazy = unicode(lazy)
     425        article = reporter.article_set.get()
     426        self.assertEqual(article.headline, notlazy)
Back to Top