From bf05da876ae711f021861849b4f6f5b80a91ee7f Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Fri, 30 Sep 2011 20:53:39 +0000 Subject: [PATCH] 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 --- tests/modeltests/model_formsets/tests.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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()