summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2007-09-15 18:13:50 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2007-09-15 18:13:50 +0000
commitf68769e1c6c5cf1ac5d3a338380c352d922febda (patch)
treec437a7d836db4d28babc1f173ff8dd32f12f338e /tests/regressiontests
parentb28be9b04d2898187a7692d6da7330dbbe448f56 (diff)
newforms-admin: Fixed #5488. inlines with multiple ForeignKeys to the same parent don't work. Thanks jdetaeye. Also, some whitespace cleanup. Sorry for the mess.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6301 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/inline_formsets/__init__.py0
-rw-r--r--tests/regressiontests/inline_formsets/models.py55
2 files changed, 55 insertions, 0 deletions
diff --git a/tests/regressiontests/inline_formsets/__init__.py b/tests/regressiontests/inline_formsets/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/regressiontests/inline_formsets/__init__.py
diff --git a/tests/regressiontests/inline_formsets/models.py b/tests/regressiontests/inline_formsets/models.py
new file mode 100644
index 0000000000..f84be84c0d
--- /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.newforms.models import inline_formset
+
+
+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 = inline_formset(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 = inline_formset(Parent, Child, fk_name='mother')
+>>> ifs = inline_formset(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 = inline_formset(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 = inline_formset(Parent, Child, fk_name='test')
+Traceback (most recent call last):
+ ...
+Exception: <class 'regressiontests.inline_formsets.models.Child'> has no field named 'test'
+
+
+"""
+}