From a19ed8aea395e8e07164ff7d85bd7dff2f24edca Mon Sep 17 00:00:00 2001 From: Brian Rosner Date: Fri, 18 Jul 2008 23:54:34 +0000 Subject: Merged the newforms-admin branch into trunk. This is a backward incompatible change. The admin contrib app has been refactored. The newforms module has several improvements including FormSets and Media definitions. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7967 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/inline_formsets/__init__.py | 0 tests/regressiontests/inline_formsets/models.py | 55 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/regressiontests/inline_formsets/__init__.py create mode 100644 tests/regressiontests/inline_formsets/models.py (limited to 'tests/regressiontests/inline_formsets') diff --git a/tests/regressiontests/inline_formsets/__init__.py b/tests/regressiontests/inline_formsets/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/inline_formsets/models.py b/tests/regressiontests/inline_formsets/models.py new file mode 100644 index 0000000000..b22f5e297d --- /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 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: has more than 1 ForeignKey to + + +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 + + +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: has no field named 'test' + + +""" +} -- cgit v1.3