Ticket #6045: 6045.solution_and_test.patch
File 6045.solution_and_test.patch, 2.6 KB (added by , 13 years ago) |
---|
-
django/db/models/fields/related.py
8 8 from django.db.models.query import QuerySet 9 9 from django.db.models.query_utils import QueryWrapper 10 10 from django.db.models.deletion import CASCADE 11 from django.utils.encoding import smart_unicode 11 from django.utils.encoding import smart_unicode, smart_str 12 12 from django.utils.translation import (ugettext_lazy as _, string_concat, 13 13 ungettext, ugettext) 14 14 from django.utils.functional import curry … … 1005 1005 assert not to._meta.abstract, "%s cannot define a relation with abstract class %s" % (self.__class__.__name__, to._meta.object_name) 1006 1006 except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT 1007 1007 assert isinstance(to, basestring), "%s(%r) is invalid. First parameter to ManyToManyField must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT) 1008 to = smart_str(to,encoding='ascii') # normalize unicode strings to ascii as it is the only acceptable encoding for getattr 1008 1009 1009 1010 kwargs['verbose_name'] = kwargs.get('verbose_name', None) 1010 1011 kwargs['rel'] = ManyToManyRel(to, -
tests/modeltests/m2m_and_m2o/tests.py
2 2 from django.test import TestCase 3 3 4 4 from models import Issue, User 5 from models import UnicodeReferenceModel 5 6 6 7 7 8 class RelatedObjectTests(TestCase): … … 73 74 ], 74 75 lambda i: i.num 75 76 ) 77 78 79 80 class RelatedObjectTests(TestCase): 81 def test_m2m_with_unicode_reference(self): 82 m1=UnicodeReferenceModel() 83 m1.save() 84 m2=UnicodeReferenceModel() 85 m2.save() # create a PK so you can use m2m 86 m2.others.add(m1) # used to cause an error (see ticket #6045) 87 m2.save() 88 for i in m2.others.all(): 89 pass # force retrieving. -
tests/modeltests/m2m_and_m2o/models.py
19 19 20 20 class Meta: 21 21 ordering = ('num',) 22 23 24 class UnicodeReferenceModel(models.Model): 25 others = models.ManyToManyField(u"UnicodeReferenceModel") 26 No newline at end of file