PageRenderTime 203ms CodeModel.GetById 101ms app.highlight 1ms RepoModel.GetById 99ms app.codeStats 0ms

/tests/modeltests/m2m_recursive/models.py

https://code.google.com/p/mango-py/
Python | 28 lines | 7 code | 4 blank | 17 comment | 0 complexity | 1f594860b75c274c663176b3dc53b139 MD5 | raw file
 1"""
 228. Many-to-many relationships between the same two tables
 3
 4In this example, a ``Person`` can have many friends, who are also ``Person``
 5objects. Friendship is a symmetrical relationship - if I am your friend, you
 6are my friend. Here, ``friends`` is an example of a symmetrical
 7``ManyToManyField``.
 8
 9A ``Person`` can also have many idols - but while I may idolize you, you may
10not think the same of me. Here, ``idols`` is an example of a non-symmetrical
11``ManyToManyField``. Only recursive ``ManyToManyField`` fields may be
12non-symmetrical, and they are symmetrical by default.
13
14This test validates that the many-to-many table is created using a mangled name
15if there is a name clash, and tests that symmetry is preserved where
16appropriate.
17"""
18
19from django.db import models
20
21
22class Person(models.Model):
23    name = models.CharField(max_length=20)
24    friends = models.ManyToManyField('self')
25    idols = models.ManyToManyField('self', symmetrical=False, related_name='stalkers')
26
27    def __unicode__(self):
28        return self.name