~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to tests/regressiontests/m2m_regress/models.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from django.db import models
 
2
from django.contrib.auth import models as auth
2
3
 
3
4
# No related name is needed here, since symmetrical relations are not
4
5
# explicitly reversible.
16
17
    def __unicode__(self):
17
18
        return self.name
18
19
 
 
20
# Regression for #11956 -- a many to many to the base class
 
21
class TagCollection(Tag):
 
22
    tags = models.ManyToManyField(Tag, related_name='tag_collections')
 
23
 
 
24
    def __unicode__(self):
 
25
        return self.name
 
26
 
19
27
# A related_name is required on one of the ManyToManyField entries here because
20
28
# they are both addressable as reverse relations from Tag.
21
29
class Entry(models.Model):
41
49
    id = models.CharField(primary_key=True, max_length=100)
42
50
    lines = models.ManyToManyField(Line, blank=True, null=True)
43
51
 
 
52
# Regression for #11226 -- A model with the same name that another one to
 
53
# which it has a m2m relation. This shouldn't cause a name clash between
 
54
# the automatically created m2m intermediary table FK field names when
 
55
# running syncdb
 
56
class User(models.Model):
 
57
    name = models.CharField(max_length=30)
 
58
    friends = models.ManyToManyField(auth.User)
 
59
 
44
60
__test__ = {"regressions": """
45
61
# Multiple m2m references to the same model or a different model must be
46
62
# distinguished when accessing the relations through an instance attribute.
93
109
>>> w.save()
94
110
>>> w.delete()
95
111
 
 
112
# Regression for #11956 -- You can add an object to a m2m with the
 
113
# base class without causing integrity errors
 
114
>>> c1 = TagCollection.objects.create(name='c1')
 
115
>>> c1.tags = [t1,t2]
 
116
 
 
117
>>> c1 = TagCollection.objects.get(name='c1')
 
118
>>> c1.tags.all()
 
119
[<Tag: t1>, <Tag: t2>]
 
120
 
 
121
>>> t1.tag_collections.all()
 
122
[<TagCollection: c1>]
 
123
 
96
124
"""
97
125
}