|
1 """ |
|
2 Regression tests for a few ForeignKey bugs. |
|
3 """ |
|
4 |
|
5 from django.db import models |
|
6 |
|
7 # If ticket #1578 ever slips back in, these models will not be able to be |
|
8 # created (the field names being lower-cased versions of their opposite |
|
9 # classes is important here). |
|
10 |
|
11 class First(models.Model): |
|
12 second = models.IntegerField() |
|
13 |
|
14 class Second(models.Model): |
|
15 first = models.ForeignKey(First, related_name = 'the_first') |
|
16 |
|
17 # Protect against repetition of #1839, #2415 and #2536. |
|
18 class Third(models.Model): |
|
19 name = models.CharField(max_length=20) |
|
20 third = models.ForeignKey('self', null=True, related_name='child_set') |
|
21 |
|
22 class Parent(models.Model): |
|
23 name = models.CharField(max_length=20) |
|
24 bestchild = models.ForeignKey('Child', null=True, related_name='favored_by') |
|
25 |
|
26 class Child(models.Model): |
|
27 name = models.CharField(max_length=20) |
|
28 parent = models.ForeignKey(Parent) |
|
29 |
|
30 |
|
31 # Multiple paths to the same model (#7110, #7125) |
|
32 class Category(models.Model): |
|
33 name = models.CharField(max_length=20) |
|
34 |
|
35 def __unicode__(self): |
|
36 return self.name |
|
37 |
|
38 class Record(models.Model): |
|
39 category = models.ForeignKey(Category) |
|
40 |
|
41 class Relation(models.Model): |
|
42 left = models.ForeignKey(Record, related_name='left_set') |
|
43 right = models.ForeignKey(Record, related_name='right_set') |
|
44 |
|
45 def __unicode__(self): |
|
46 return u"%s - %s" % (self.left.category.name, self.right.category.name) |