Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #9171 -- Fixed a few places where we were assuming lists instea…

…d of

generic sequences in ModelForm structures. Patch from mrmachine.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@9086 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6c7cf34d691ffe9ac2c9a7be8d2838b205ace757 1 parent edabc4a
@malcolmt malcolmt authored
View
4 django/contrib/admin/options.py
@@ -266,7 +266,7 @@ def get_form(self, request, obj=None, **kwargs):
if self.exclude is None:
exclude = []
else:
- exclude = self.exclude
+ exclude = list(self.exclude)
defaults = {
"form": self.form,
"fields": fields,
@@ -780,7 +780,7 @@ def get_formset(self, request, obj=None, **kwargs):
if self.exclude is None:
exclude = []
else:
- exclude = self.exclude
+ exclude = list(self.exclude)
defaults = {
"form": self.form,
"formset": self.formset,
View
1  django/forms/models.py
@@ -528,6 +528,7 @@ def inlineformset_factory(parent_model, model, form=ModelForm,
if fk.unique:
max_num = 1
if exclude is not None:
+ exclude = list(exclude)
exclude.append(fk.name)
else:
exclude = [fk.name]
View
2  tests/regressiontests/inline_formsets/models.py
@@ -51,5 +51,7 @@ class Child(models.Model):
Exception: <class 'regressiontests.inline_formsets.models.Child'> has no field named 'test'
+# Regression test for #9171.
+>>> ifs = inlineformset_factory(Parent, Child, exclude=('school',), fk_name='mother')
"""
}
View
8 tests/regressiontests/modeladmin/models.py
@@ -123,6 +123,14 @@ class and an AdminSite instance, so let's just go ahead and do that manually
>>> ma = BandAdmin(Band, site)
>>> ma.get_form(request).base_fields.keys()
['name', 'sign_date']
+
+# You can also pass a tuple to `exclude`.
+
+>>> class BandAdmin(ModelAdmin):
+... exclude = ('bio',)
+>>> ma = BandAdmin(Band, site)
+>>> ma.get_form(request).base_fields.keys()
+['name', 'sign_date']
# Using `fields` and `exclude`.
Please sign in to comment.
Something went wrong with that request. Please try again.