File: models.py

package info (click to toggle)
python-django 1.2.3-3%2Bsqueeze15
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 29,720 kB
  • ctags: 21,538
  • sloc: python: 101,631; xml: 574; makefile: 149; sh: 121; sql: 7
file content (70 lines) | stat: -rw-r--r-- 2,115 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# coding: utf-8
from django.db import models

class School(models.Model):
    name = models.CharField(max_length=100)

class Parent(models.Model):
    name = models.CharField(max_length=100)

class Child(models.Model):
    mother = models.ForeignKey(Parent, related_name='mothers_children')
    father = models.ForeignKey(Parent, related_name='fathers_children')
    school = models.ForeignKey(School)
    name = models.CharField(max_length=100)

class Poet(models.Model):
    name = models.CharField(max_length=100)

    def __unicode__(self):
        return self.name

class Poem(models.Model):
    poet = models.ForeignKey(Poet)
    name = models.CharField(max_length=100)

    def __unicode__(self):
        return self.name

__test__ = {'API_TESTS': """

>>> from django.forms.models import inlineformset_factory


Child has two ForeignKeys to Parent, so if we don't specify which one to use
for the inline formset, we should get an exception.

>>> ifs = inlineformset_factory(Parent, Child)
Traceback (most recent call last):
    ...
Exception: <class 'regressiontests.inline_formsets.models.Child'> has more than 1 ForeignKey to <class 'regressiontests.inline_formsets.models.Parent'>


These two should both work without a problem.

>>> ifs = inlineformset_factory(Parent, Child, fk_name='mother')
>>> ifs = inlineformset_factory(Parent, Child, fk_name='father')


If we specify fk_name, but it isn't a ForeignKey from the child model to the
parent model, we should get an exception.

>>> ifs = inlineformset_factory(Parent, Child, fk_name='school')
Traceback (most recent call last):
    ...
Exception: fk_name 'school' is not a ForeignKey to <class 'regressiontests.inline_formsets.models.Parent'>


If the field specified in fk_name is not a ForeignKey, we should get an
exception.

>>> ifs = inlineformset_factory(Parent, Child, fk_name='test')
Traceback (most recent call last):
    ...
Exception: <class 'regressiontests.inline_formsets.models.Child'> has no field named 'test'


# Regression test for #9171.
>>> ifs = inlineformset_factory(Parent, Child, exclude=('school',), fk_name='mother')
"""
}