~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to tests/regressiontests/many_to_one_regress/models.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

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