Skip to content
Browse files

Fixed #8160 -- Made sure `modelformset_factory` takes in account `fie…

…lds' 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
  • Loading branch information...
1 parent 10d90cb commit bf05da876ae711f021861849b4f6f5b80a91ee7f @ramiro ramiro committed
Showing with 23 additions and 1 deletion.
  1. +23 −1 tests/modeltests/model_formsets/tests.py
View
24 tests/modeltests/model_formsets/tests.py
@@ -6,7 +6,7 @@
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 @@ def save(self, commit=True):
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()

0 comments on commit bf05da8

Please sign in to comment.
Something went wrong with that request. Please try again.