summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-05-13 14:32:18 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-05-13 14:32:18 +0000
commitc48285910533e5443bba3f8a03a2ac9d82856e52 (patch)
treea26f563ee6f36bdd5b38814a4f3660eed886d854 /tests
parent17d214a9821542696b4b632b1fc70086ed2f7ecc (diff)
downloaddjango-c48285910533e5443bba3f8a03a2ac9d82856e52.tar.gz
[1.0.X] Fixed #10243, #11043 -- Corrected handling of formsets over a ForeignKey that uses to_field, and by extension, fixed the admin for handling fields of that type. Thanks to apollo13 for the initial patch.
Merge of r10756 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10758 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/model_formsets_regress/__init__.py0
-rw-r--r--tests/regressiontests/model_formsets_regress/models.py9
-rw-r--r--tests/regressiontests/model_formsets_regress/tests.py24
3 files changed, 33 insertions, 0 deletions
diff --git a/tests/regressiontests/model_formsets_regress/__init__.py b/tests/regressiontests/model_formsets_regress/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/regressiontests/model_formsets_regress/__init__.py
diff --git a/tests/regressiontests/model_formsets_regress/models.py b/tests/regressiontests/model_formsets_regress/models.py
new file mode 100644
index 0000000000..51fc6a49ab
--- /dev/null
+++ b/tests/regressiontests/model_formsets_regress/models.py
@@ -0,0 +1,9 @@
+from django.db import models
+
+class User(models.Model):
+ username = models.CharField(max_length=12, unique=True)
+ serial = models.IntegerField()
+
+class UserSite(models.Model):
+ user = models.ForeignKey(User, to_field="username")
+ data = models.IntegerField()
diff --git a/tests/regressiontests/model_formsets_regress/tests.py b/tests/regressiontests/model_formsets_regress/tests.py
new file mode 100644
index 0000000000..c20c1f4077
--- /dev/null
+++ b/tests/regressiontests/model_formsets_regress/tests.py
@@ -0,0 +1,24 @@
+from django.forms.models import inlineformset_factory
+from django.test import TestCase
+
+from models import User, UserSite
+
+class InlineFormsetTests(TestCase):
+ def test_formset_over_to_field(self):
+ "A formset over a ForeignKey with a to_field can be saved. Regression for #10243"
+ FormSet = inlineformset_factory(User, UserSite)
+ user = User.objects.create(serial=1, username='apollo13')
+ user.save()
+ data = {
+ 'usersite_set-TOTAL_FORMS': u'1',
+ 'usersite_set-INITIAL_FORMS': u'0',
+ 'usersite_set-0-data': u'10',
+ 'usersite_set-0-user': u'apollo13'
+ }
+ form_set = FormSet(data, instance=user)
+ if form_set.is_valid():
+ form_set.save()
+ usersite = UserSite.objects.all().values()[0]
+ self.assertEqual(usersite, {'data': 10, 'user_id': u'apollo13', 'id': 1})
+ else:
+ self.fail('Errors found on form:%s' % form_set.errors) \ No newline at end of file