2010-02-22 15:04:13 +01:00
|
|
|
from django.contrib.auth import models as auth
|
2011-10-13 23:34:56 +02:00
|
|
|
from django.db import models
|
2012-08-12 12:32:08 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2008-08-29 23:24:00 +02:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2008-08-29 23:24:00 +02:00
|
|
|
# No related name is needed here, since symmetrical relations are not
|
|
|
|
# explicitly reversible.
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2008-08-29 23:24:00 +02:00
|
|
|
class SelfRefer(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
references = models.ManyToManyField('self')
|
|
|
|
related = models.ManyToManyField('self')
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2008-08-29 23:24:00 +02:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2008-08-29 23:24:00 +02:00
|
|
|
class Tag(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2008-08-29 23:24:00 +02:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2010-04-02 17:44:48 +02:00
|
|
|
# Regression for #11956 -- a many to many to the base class
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2010-04-02 17:44:48 +02:00
|
|
|
class TagCollection(Tag):
|
|
|
|
tags = models.ManyToManyField(Tag, related_name='tag_collections')
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2010-04-02 17:44:48 +02:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2008-08-29 23:24:00 +02:00
|
|
|
# A related_name is required on one of the ManyToManyField entries here because
|
|
|
|
# they are both addressable as reverse relations from Tag.
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2008-08-29 23:24:00 +02:00
|
|
|
class Entry(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
topics = models.ManyToManyField(Tag)
|
|
|
|
related = models.ManyToManyField(Tag, related_name="similar")
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2008-08-29 23:24:00 +02:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2009-04-13 04:59:40 +02:00
|
|
|
# Two models both inheriting from a base model with a self-referential m2m field
|
|
|
|
class SelfReferChild(SelfRefer):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2009-04-13 04:59:40 +02:00
|
|
|
class SelfReferChildSibling(SelfRefer):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2009-06-15 13:47:01 +02:00
|
|
|
# Many-to-Many relation between models, where one of the PK's isn't an Autofield
|
|
|
|
class Line(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2009-06-15 13:47:01 +02:00
|
|
|
class Worksheet(models.Model):
|
|
|
|
id = models.CharField(primary_key=True, max_length=100)
|
|
|
|
lines = models.ManyToManyField(Line, blank=True, null=True)
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2010-02-22 15:04:13 +01:00
|
|
|
# Regression for #11226 -- A model with the same name that another one to
|
|
|
|
# which it has a m2m relation. This shouldn't cause a name clash between
|
|
|
|
# the automatically created m2m intermediary table FK field names when
|
2013-09-03 17:51:34 +02:00
|
|
|
# running migrate
|
2010-02-22 15:04:13 +01:00
|
|
|
class User(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
|
|
|
friends = models.ManyToManyField(auth.User)
|
2012-11-04 22:43:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
class BadModelWithSplit(models.Model):
|
|
|
|
name = models.CharField(max_length=1)
|
|
|
|
|
|
|
|
def split(self):
|
|
|
|
raise RuntimeError('split should not be called')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
|
|
|
|
class RegressionModelSplit(BadModelWithSplit):
|
|
|
|
"""
|
|
|
|
Model with a split method should not cause an error in add_lazy_relation
|
|
|
|
"""
|
|
|
|
others = models.ManyToManyField('self')
|