Ticket #12321: unicode_charfield.diff
File unicode_charfield.diff, 2.2 KB (added by , 15 years ago) |
---|
-
django/db/models/fields/__init__.py
377 377 return force_unicode(self.default, strings_only=True) 378 378 if not self.empty_strings_allowed or (self.null and not connection.features.interprets_empty_strings_as_nulls): 379 379 return None 380 return ""380 return u"" 381 381 382 382 def get_validator_unique_lookup_type(self): 383 383 return '%s__exact' % self.name … … 565 565 return "CharField" 566 566 567 567 def to_python(self, value): 568 if isinstance(value, basestring) or value is None:568 if isinstance(value, unicode) or value is None: 569 569 return value 570 570 return smart_unicode(value) 571 571 -
tests/regressiontests/model_fields/tests.py
126 126 f = models.BooleanField(choices=choices, default=1, null=False) 127 127 self.assertEqual(f.formfield().choices, choices) 128 128 129 class CharFieldTests(django.test.TestCase): 130 def test_to_python(self): 131 f = models.CharField() 132 self.assertEqual(f.to_python(u"test"), u"test") 133 self.assertEqual(type(f.to_python(u"test")), unicode) 134 135 def test_to_python_extended(self): 136 f = models.CharField() 137 self.assertEqual(f.to_python(u"ni\u223ca"), u"ni\u223ca") 138 139 def test_default(self): 140 empty_f = models.CharField() 141 self.assertEqual(empty_f.to_python(""), u"") 142 self.assertEqual(type(empty_f.get_default()), unicode) 143 144 str_f = models.CharField(default="my_default") 145 self.assertEqual(str_f.get_default(), u"my_default") 146 self.assertEqual(type(str_f.get_default()), unicode) 147 148 uni_f = models.CharField(default=u"my_default") 149 self.assertEqual(uni_f.get_default(), u"my_default") 150 self.assertEqual(type(uni_f.get_default()), unicode) 151 152 129 153 class ChoicesTests(django.test.TestCase): 130 154 def test_choices_and_field_display(self): 131 155 """