Ticket #6045: test_for_6045_worksforme.diff
File test_for_6045_worksforme.diff, 2.2 KB (added by , 14 years ago) |
---|
-
tests/regressiontests/m2m_regress/tests.py
2 2 from django.test import TestCase 3 3 4 4 from models import (SelfRefer, Tag, TagCollection, Entry, SelfReferChild, 5 SelfReferChildSibling, Worksheet )5 SelfReferChildSibling, Worksheet, Story, Life) 6 6 7 7 8 8 class M2MRegressionTests(TestCase): … … 73 73 74 74 self.assertQuerysetEqual(c1.tags.all(), ["<Tag: t1>", "<Tag: t2>"]) 75 75 self.assertQuerysetEqual(t1.tag_collections.all(), ["<TagCollection: c1>"]) 76 77 def test_m2m_unicode(self): 78 # Regression for #6045 - You can an Unicode string as first argument 79 # or as related_name in a ManyToManyField 80 81 s = Story.objects.create(name='birth of Fred') 82 s.save() 83 84 l = Life.objects.create(name='mother of Fred') 85 l.stories = [s] 86 l.save() 87 88 l = Life.objects.create(name='father of Fred') 89 l.stories = [s] 90 l.save() 91 92 self.assertQuerysetEqual(l.stories.all(), ["<Story: birth of Fred>"]) 93 self.assertQuerysetEqual(s.witnesses.all(), ["<Life: mother of Fred>", 94 "<Life: father of Fred>"]) -
tests/regressiontests/m2m_regress/models.py
56 56 class User(models.Model): 57 57 name = models.CharField(max_length=30) 58 58 friends = models.ManyToManyField(auth.User) 59 60 # Regression for #6045 - A model with ManyToManyField whose first argument 61 # or whose related_name is an Unicode string 62 class Story(models.Model): 63 name = models.CharField(max_length=100) 64 65 def __unicode__(self): 66 return self.name 67 68 class Life(models.Model): 69 name = models.CharField(max_length=100) 70 stories = models.ManyToManyField(u'Story', related_name=u'witnesses') 71 72 def __unicode__(self): 73 return self.name