Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit bf05da876ae711f021861849b4f6f5b80a91ee7f 1 parent 10d90cb
@ramiro ramiro authored
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()
Please sign in to comment.
Something went wrong with that request. Please try again.