parts/django/tests/regressiontests/m2m_regress/models.py
changeset 69 c6bca38c1cbf
equal deleted inserted replaced
68:5ff1fc726848 69:c6bca38c1cbf
       
     1 from django.db import models
       
     2 from django.contrib.auth import models as auth
       
     3 
       
     4 # No related name is needed here, since symmetrical relations are not
       
     5 # explicitly reversible.
       
     6 class 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 
       
    14 class 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
       
    21 class 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.
       
    29 class 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
       
    38 class SelfReferChild(SelfRefer):
       
    39     pass
       
    40 
       
    41 class SelfReferChildSibling(SelfRefer):
       
    42     pass
       
    43 
       
    44 # Many-to-Many relation between models, where one of the PK's isn't an Autofield
       
    45 class Line(models.Model):
       
    46     name = models.CharField(max_length=100)
       
    47 
       
    48 class 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
       
    56 class User(models.Model):
       
    57     name = models.CharField(max_length=30)
       
    58     friends = models.ManyToManyField(auth.User)