summaryrefslogtreecommitdiff
path: root/tests/regressiontests/inline_formsets/models.py
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2008-07-19 13:30:47 +0000
committerJustin Bronn <jbronn@gmail.com>2008-07-19 13:30:47 +0000
commit149e731c3c5a2cc96b7d3c72070401df6c2a238e (patch)
tree2a819f695246ab36139b7f8846085c9df1563bd8 /tests/regressiontests/inline_formsets/models.py
parent5bf3565a263533e37b2e1217e8d447cb7e02f5b4 (diff)
gis: Merged revisions 7921,7926-7928,7938-7941,7945-7947,7949-7950,7952,7955-7956,7961,7964-7968,7970-7978 via svnmerge from trunk.
This includes the newforms-admin branch, and thus is backwards-incompatible. The geographic admin is _not_ in this changeset, and is forthcoming. git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7979 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/inline_formsets/models.py')
-rw-r--r--tests/regressiontests/inline_formsets/models.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/regressiontests/inline_formsets/models.py b/tests/regressiontests/inline_formsets/models.py
new file mode 100644
index 0000000000..c00703852f
--- /dev/null
+++ b/tests/regressiontests/inline_formsets/models.py
@@ -0,0 +1,55 @@
+# 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)
+
+__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'
+
+
+"""
+}