PageRenderTime 157ms CodeModel.GetById 81ms app.highlight 18ms RepoModel.GetById 52ms app.codeStats 1ms

/tests/regressiontests/m2m_regress/models.py

https://code.google.com/p/mango-py/
Python | 58 lines | 34 code | 13 blank | 11 comment | 0 complexity | 70725d7de962c1d7b02f7d2ec6dcaaf9 MD5 | raw file
 1from django.db import models
 2from django.contrib.auth import models as auth
 3
 4# No related name is needed here, since symmetrical relations are not
 5# explicitly reversible.
 6class SelfRefer(models.Model):
 7    name = models.CharField(max_length=10)
 8    references = models.ManyToManyField('self')
 9    related = models.ManyToManyField('self')
10
11    def __unicode__(self):
12        return self.name
13
14class Tag(models.Model):
15    name = models.CharField(max_length=10)
16
17    def __unicode__(self):
18        return self.name
19
20# Regression for #11956 -- a many to many to the base class
21class TagCollection(Tag):
22    tags = models.ManyToManyField(Tag, related_name='tag_collections')
23
24    def __unicode__(self):
25        return self.name
26
27# A related_name is required on one of the ManyToManyField entries here because
28# they are both addressable as reverse relations from Tag.
29class Entry(models.Model):
30    name = models.CharField(max_length=10)
31    topics = models.ManyToManyField(Tag)
32    related = models.ManyToManyField(Tag, related_name="similar")
33
34    def __unicode__(self):
35        return self.name
36
37# Two models both inheriting from a base model with a self-referential m2m field
38class SelfReferChild(SelfRefer):
39    pass
40
41class SelfReferChildSibling(SelfRefer):
42    pass
43
44# Many-to-Many relation between models, where one of the PK's isn't an Autofield
45class Line(models.Model):
46    name = models.CharField(max_length=100)
47
48class Worksheet(models.Model):
49    id = models.CharField(primary_key=True, max_length=100)
50    lines = models.ManyToManyField(Line, blank=True, null=True)
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
56class User(models.Model):
57    name = models.CharField(max_length=30)
58    friends = models.ManyToManyField(auth.User)