~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant, Eddy Mulyono
  • Date: 2008-09-16 12:18:47 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080916121847-mg225rg5mnsdqzr0
Tags: 1.0-1ubuntu1
* Merge from Debian (LP: #264191), remaining changes:
  - Run test suite on build.

[Eddy Mulyono]
* Update patch to workaround network test case failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# coding: utf-8
 
2
from django.db import models
 
3
 
 
4
class School(models.Model):
 
5
    name = models.CharField(max_length=100)
 
6
 
 
7
class Parent(models.Model):
 
8
    name = models.CharField(max_length=100)
 
9
 
 
10
class Child(models.Model):
 
11
    mother = models.ForeignKey(Parent, related_name='mothers_children')
 
12
    father = models.ForeignKey(Parent, related_name='fathers_children')
 
13
    school = models.ForeignKey(School)
 
14
    name = models.CharField(max_length=100)
 
15
 
 
16
__test__ = {'API_TESTS': """
 
17
 
 
18
>>> from django.forms.models import inlineformset_factory
 
19
 
 
20
 
 
21
Child has two ForeignKeys to Parent, so if we don't specify which one to use
 
22
for the inline formset, we should get an exception.
 
23
 
 
24
>>> ifs = inlineformset_factory(Parent, Child)
 
25
Traceback (most recent call last):
 
26
    ...
 
27
Exception: <class 'regressiontests.inline_formsets.models.Child'> has more than 1 ForeignKey to <class 'regressiontests.inline_formsets.models.Parent'>
 
28
 
 
29
 
 
30
These two should both work without a problem.
 
31
 
 
32
>>> ifs = inlineformset_factory(Parent, Child, fk_name='mother')
 
33
>>> ifs = inlineformset_factory(Parent, Child, fk_name='father')
 
34
 
 
35
 
 
36
If we specify fk_name, but it isn't a ForeignKey from the child model to the
 
37
parent model, we should get an exception.
 
38
 
 
39
>>> ifs = inlineformset_factory(Parent, Child, fk_name='school')
 
40
Traceback (most recent call last):
 
41
    ...
 
42
Exception: fk_name 'school' is not a ForeignKey to <class 'regressiontests.inline_formsets.models.Parent'>
 
43
 
 
44
 
 
45
If the field specified in fk_name is not a ForeignKey, we should get an
 
46
exception.
 
47
 
 
48
>>> ifs = inlineformset_factory(Parent, Child, fk_name='test')
 
49
Traceback (most recent call last):
 
50
    ...
 
51
Exception: <class 'regressiontests.inline_formsets.models.Child'> has no field named 'test'
 
52
 
 
53
 
 
54
"""
 
55
}