Author: russellm
Date: 2011-08-23 08:56:40 -0700 (Tue, 23 Aug 2011)
New Revision: 16675

Modified:
   django/branches/releases/1.3.X/django/db/models/options.py
   
django/branches/releases/1.3.X/tests/modeltests/invalid_models/invalid_models/models.py
Log:
[1.3.X] Fixed #16299 -- Ensure that unicode strings can be used to identify 
classes in ForeignKey and ManyToManyFields. Unicode strings aren't actually 
legal as class names, but this is an issue if you use from __future__ import 
unicode_literals in your models.py file. Thanks to Martijn Bastiaan for the 
report, and Anthony Briggs for the final patch.

Backport of r16663 from trunk.

Modified: django/branches/releases/1.3.X/django/db/models/options.py
===================================================================
--- django/branches/releases/1.3.X/django/db/models/options.py  2011-08-23 
15:56:18 UTC (rev 16674)
+++ django/branches/releases/1.3.X/django/db/models/options.py  2011-08-23 
15:56:40 UTC (rev 16675)
@@ -390,7 +390,7 @@
                     cache[obj] = model
         for klass in get_models(include_auto_created=True):
             for f in klass._meta.local_fields:
-                if f.rel and not isinstance(f.rel.to, str) and self == 
f.rel.to._meta:
+                if f.rel and not isinstance(f.rel.to, basestring) and self == 
f.rel.to._meta:
                     cache[RelatedObject(f.rel.to, klass, f)] = None
         self._related_objects_cache = cache
 
@@ -427,7 +427,7 @@
                     cache[obj] = model
         for klass in get_models():
             for f in klass._meta.local_many_to_many:
-                if f.rel and not isinstance(f.rel.to, str) and self == 
f.rel.to._meta:
+                if f.rel and not isinstance(f.rel.to, basestring) and self == 
f.rel.to._meta:
                     cache[RelatedObject(f.rel.to, klass, f)] = None
         if app_cache_ready():
             self._related_many_to_many_cache = cache

Modified: 
django/branches/releases/1.3.X/tests/modeltests/invalid_models/invalid_models/models.py
===================================================================
--- 
django/branches/releases/1.3.X/tests/modeltests/invalid_models/invalid_models/models.py
     2011-08-23 15:56:18 UTC (rev 16674)
+++ 
django/branches/releases/1.3.X/tests/modeltests/invalid_models/invalid_models/models.py
     2011-08-23 15:56:40 UTC (rev 16675)
@@ -1,3 +1,4 @@
+#encoding=utf-8
 """
 26. Invalid models
 
@@ -218,6 +219,16 @@
 class InvalidSetDefault(models.Model):
     fk = models.ForeignKey('self', on_delete=models.SET_DEFAULT)
 
+class UnicodeForeignKeys(models.Model):
+    """Foreign keys which can translate to ascii should be OK, but fail if 
they're not."""
+    good = models.ForeignKey(u'FKTarget')
+    also_good = models.ManyToManyField(u'FKTarget', related_name='unicode2')
+
+    # In Python 3 this should become legal, but currently causes unicode errors
+    # when adding the errors in core/management/validation.py
+    #bad = models.ForeignKey(u'★')
+
+
 model_errors = """invalid_models.fielderrors: "charfield": CharFields require 
a "max_length" attribute that is a positive integer.
 invalid_models.fielderrors: "charfield2": CharFields require a "max_length" 
attribute that is a positive integer.
 invalid_models.fielderrors: "charfield3": CharFields require a "max_length" 
attribute that is a positive integer.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to