From 0a8b911582eee85ea6da0d40dd2c7b12de5a78b2 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Thu, 11 Dec 2014 17:28:03 -0700 Subject: [1.7.x] Fixed #23455 -- Accept either bytes or text for related_name, convert to text. Backport of c72eb80d114fb5d90bd21b5549e8abd0bbd17f99 from master. --- tests/model_fields/models.py | 2 +- tests/model_fields/tests.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'tests/model_fields') diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py index f53c45c693..f8f935471c 100644 --- a/tests/model_fields/models.py +++ b/tests/model_fields/models.py @@ -26,7 +26,7 @@ def get_foo(): class Bar(models.Model): b = models.CharField(max_length=10) - a = models.ForeignKey(Foo, default=get_foo) + a = models.ForeignKey(Foo, default=get_foo, related_name=b'bars') class Whiz(models.Model): diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index 03aae7544c..53c3b301c7 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -181,6 +181,10 @@ class ForeignKeyTests(test.TestCase): fk_model_empty = FkToChar.objects.select_related('out').get(id=fk_model_empty.pk) self.assertEqual(fk_model_empty.out, char_model_empty) + def test_related_name_converted_to_text(self): + rel_name = Bar._meta.get_field_by_name('a')[0].rel.related_name + self.assertIsInstance(rel_name, six.text_type) + class DateTimeFieldTests(unittest.TestCase): def test_datetimefield_to_python_usecs(self): -- cgit v1.3