2008-06-05 02:39:32 +02:00
|
|
|
"""
|
2009-03-06 05:51:05 +01:00
|
|
|
Regression tests for a few ForeignKey bugs.
|
2008-06-05 02:39:32 +02:00
|
|
|
"""
|
2012-06-07 18:08:47 +02:00
|
|
|
from __future__ import unicode_literals
|
2008-06-05 02:39:32 +02:00
|
|
|
|
2006-07-04 12:48:07 +02:00
|
|
|
from django.db import models
|
2012-08-12 12:32:08 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2006-07-04 12:48:07 +02:00
|
|
|
|
2007-03-08 04:21:35 +01: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).
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2006-07-04 12:48:07 +02:00
|
|
|
class First(models.Model):
|
|
|
|
second = models.IntegerField()
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2006-07-04 12:48:07 +02:00
|
|
|
class Second(models.Model):
|
2013-11-03 05:36:09 +01:00
|
|
|
first = models.ForeignKey(First, related_name='the_first')
|
|
|
|
|
2006-07-04 12:48:07 +02:00
|
|
|
|
2007-03-08 04:21:35 +01:00
|
|
|
# Protect against repetition of #1839, #2415 and #2536.
|
|
|
|
class Third(models.Model):
|
2007-08-05 07:14:46 +02:00
|
|
|
name = models.CharField(max_length=20)
|
2007-03-08 04:21:35 +01:00
|
|
|
third = models.ForeignKey('self', null=True, related_name='child_set')
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2007-03-08 04:21:35 +01:00
|
|
|
class Parent(models.Model):
|
2007-08-05 07:14:46 +02:00
|
|
|
name = models.CharField(max_length=20)
|
2007-03-08 04:21:35 +01:00
|
|
|
bestchild = models.ForeignKey('Child', null=True, related_name='favored_by')
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2007-03-08 04:21:35 +01:00
|
|
|
class Child(models.Model):
|
2007-08-05 07:14:46 +02:00
|
|
|
name = models.CharField(max_length=20)
|
2007-03-08 04:21:35 +01:00
|
|
|
parent = models.ForeignKey(Parent)
|
|
|
|
|
2006-07-04 12:48:07 +02:00
|
|
|
|
2008-06-29 04:36:18 +02:00
|
|
|
# Multiple paths to the same model (#7110, #7125)
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2008-06-29 04:36:18 +02:00
|
|
|
class Category(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2008-06-29 04:36:18 +02:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2008-06-29 04:36:18 +02:00
|
|
|
class Record(models.Model):
|
|
|
|
category = models.ForeignKey(Category)
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2008-06-29 04:36:18 +02:00
|
|
|
class Relation(models.Model):
|
|
|
|
left = models.ForeignKey(Record, related_name='left_set')
|
|
|
|
right = models.ForeignKey(Record, related_name='right_set')
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2012-06-07 18:08:47 +02:00
|
|
|
return "%s - %s" % (self.left.category.name, self.right.category.name)
|
2013-01-06 17:40:56 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-01-06 17:40:56 +01:00
|
|
|
class Car(models.Model):
|
|
|
|
make = models.CharField(max_length=100, null=True, unique=True)
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-01-06 17:40:56 +01:00
|
|
|
class Driver(models.Model):
|
|
|
|
car = models.ForeignKey(Car, to_field='make', null=True, related_name='drivers')
|