Ticket #6045: test_for_6045_worksforme.diff

File test_for_6045_worksforme.diff, 2.2 KB (added by Aymeric Augustin, 14 years ago)
  • tests/regressiontests/m2m_regress/tests.py

     
    22from django.test import TestCase
    33
    44from models import (SelfRefer, Tag, TagCollection, Entry, SelfReferChild,
    5     SelfReferChildSibling, Worksheet)
     5    SelfReferChildSibling, Worksheet, Story, Life)
    66
    77
    88class M2MRegressionTests(TestCase):
     
    7373
    7474        self.assertQuerysetEqual(c1.tags.all(), ["<Tag: t1>", "<Tag: t2>"])
    7575        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

     
    5656class User(models.Model):
    5757    name = models.CharField(max_length=30)
    5858    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
     62class Story(models.Model):
     63    name = models.CharField(max_length=100)
     64
     65    def __unicode__(self):
     66        return self.name
     67
     68class 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
Back to Top