PageRenderTime 176ms CodeModel.GetById 166ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/many_to_one_regress/models.py

https://code.google.com/p/mango-py/
Python | 46 lines | 25 code | 13 blank | 8 comment | 0 complexity | c4f0e25b523aa5fe3141b47c7d3196c6 MD5 | raw file
 1"""
 2Regression tests for a few ForeignKey bugs.
 3"""
 4
 5from 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
11class First(models.Model):
12    second = models.IntegerField()
13
14class Second(models.Model):
15    first = models.ForeignKey(First, related_name = 'the_first')
16
17# Protect against repetition of #1839, #2415 and #2536.
18class Third(models.Model):
19    name = models.CharField(max_length=20)
20    third = models.ForeignKey('self', null=True, related_name='child_set')
21
22class Parent(models.Model):
23    name = models.CharField(max_length=20)
24    bestchild = models.ForeignKey('Child', null=True, related_name='favored_by')
25
26class 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)
32class Category(models.Model):
33    name = models.CharField(max_length=20)
34
35    def __unicode__(self):
36        return self.name
37
38class Record(models.Model):
39    category = models.ForeignKey(Category)
40
41class 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)