summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2011-09-30 20:53:39 +0000
committerRamiro Morales <cramm0@gmail.com>2011-09-30 20:53:39 +0000
commitbf05da876ae711f021861849b4f6f5b80a91ee7f (patch)
treef6bcadab4bd977906fbbf989fc98575825d9d426 /tests
parent10d90cba83d5dfbe52eb5501279c3db71b42dd41 (diff)
Fixed #8160 -- Made sure `modelformset_factory` takes in account `fields' and `exclude` ModelForm options.
Thanks Andrew McMurry for the report and Claude Paroz for creating these tests. (Actually, this had been fixed in r10619 but the tests added then exercise the code in the context of ModelAdmin. This commit adds more generic tests.) git-svn-id: http://code.djangoproject.com/svn/django/trunk@16918 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/model_formsets/tests.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/modeltests/model_formsets/tests.py b/tests/modeltests/model_formsets/tests.py
index 34f8d47755..0e4f2f5991 100644
--- a/tests/modeltests/model_formsets/tests.py
+++ b/tests/modeltests/model_formsets/tests.py
@@ -6,7 +6,7 @@ from decimal import Decimal
from django import forms
from django.db import models
from django.forms.models import (_get_foreign_key, inlineformset_factory,
- modelformset_factory, modelformset_factory)
+ modelformset_factory)
from django.test import TestCase, skipUnlessDBFeature
from modeltests.model_formsets.models import (
@@ -353,6 +353,28 @@ class ModelFormsetTest(TestCase):
self.assertEqual(poet1.name, 'Vladimir Mayakovsky')
self.assertEqual(poet2.name, 'Vladimir Mayakovsky')
+ def test_custom_form(self):
+ """ Test that model_formset respects fields and exclude parameters of
+ custom form
+ """
+ class PostForm1(forms.ModelForm):
+ class Meta:
+ model = Post
+ fields = ('title', 'posted')
+
+ class PostForm2(forms.ModelForm):
+ class Meta:
+ model = Post
+ exclude = ('subtitle',)
+
+ PostFormSet = modelformset_factory(Post, form=PostForm1)
+ formset = PostFormSet()
+ self.assertFalse("subtitle" in formset.forms[0].fields)
+
+ PostFormSet = modelformset_factory(Post, form=PostForm2)
+ formset = PostFormSet()
+ self.assertFalse("subtitle" in formset.forms[0].fields)
+
def test_model_inheritance(self):
BetterAuthorFormSet = modelformset_factory(BetterAuthor)
formset = BetterAuthorFormSet()