2008-06-05 08:39:32 +08:00
|
|
|
"""
|
2009-03-06 12:51:05 +08:00
|
|
|
Regression tests for a few ForeignKey bugs.
|
2008-06-05 08:39:32 +08:00
|
|
|
"""
|
|
|
|
|
2006-07-04 18:48:07 +08:00
|
|
|
from django.db import models
|
|
|
|
|
2007-03-08 11:21:35 +08:00
|
|
|
# If ticket #1578 ever slips back in, these models will not be able to be
|
|
|
|
# created (the field names being lower-cased versions of their opposite
|
|
|
|
# classes is important here).
|
|
|
|
|
2006-07-04 18:48:07 +08:00
|
|
|
class First(models.Model):
|
|
|
|
second = models.IntegerField()
|
|
|
|
|
|
|
|
class Second(models.Model):
|
|
|
|
first = models.ForeignKey(First, related_name = 'the_first')
|
|
|
|
|
2007-03-08 11:21:35 +08:00
|
|
|
# Protect against repetition of #1839, #2415 and #2536.
|
|
|
|
class Third(models.Model):
|
2007-08-05 13:14:46 +08:00
|
|
|
name = models.CharField(max_length=20)
|
2007-03-08 11:21:35 +08:00
|
|
|
third = models.ForeignKey('self', null=True, related_name='child_set')
|
|
|
|
|
|
|
|
class Parent(models.Model):
|
2007-08-05 13:14:46 +08:00
|
|
|
name = models.CharField(max_length=20)
|
2007-03-08 11:21:35 +08:00
|
|
|
bestchild = models.ForeignKey('Child', null=True, related_name='favored_by')
|
|
|
|
|
|
|
|
class Child(models.Model):
|
2007-08-05 13:14:46 +08:00
|
|
|
name = models.CharField(max_length=20)
|
2007-03-08 11:21:35 +08:00
|
|
|
parent = models.ForeignKey(Parent)
|
|
|
|
|
2006-07-04 18:48:07 +08:00
|
|
|
|
2008-06-29 10:36:18 +08:00
|
|
|
# Multiple paths to the same model (#7110, #7125)
|
|
|
|
class Category(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Record(models.Model):
|
|
|
|
category = models.ForeignKey(Category)
|
|
|
|
|
|
|
|
class Relation(models.Model):
|
|
|
|
left = models.ForeignKey(Record, related_name='left_set')
|
|
|
|
right = models.ForeignKey(Record, related_name='right_set')
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u"%s - %s" % (self.left.category.name, self.right.category.name)
|