From 6c7cf34d691ffe9ac2c9a7be8d2838b205ace757 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sat, 27 Sep 2008 05:57:10 +0000 Subject: [PATCH] Fixed #9171 -- Fixed a few places where we were assuming lists instead 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 --- django/contrib/admin/options.py | 4 ++-- django/forms/models.py | 1 + tests/regressiontests/inline_formsets/models.py | 2 ++ tests/regressiontests/modeladmin/models.py | 8 ++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 0281fa84d6..019bfe9789 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -266,7 +266,7 @@ class ModelAdmin(BaseModelAdmin): if self.exclude is None: exclude = [] else: - exclude = self.exclude + exclude = list(self.exclude) defaults = { "form": self.form, "fields": fields, @@ -780,7 +780,7 @@ class InlineModelAdmin(BaseModelAdmin): if self.exclude is None: exclude = [] else: - exclude = self.exclude + exclude = list(self.exclude) defaults = { "form": self.form, "formset": self.formset, diff --git a/django/forms/models.py b/django/forms/models.py index 6024a1c6c8..dad3483455 100644 --- a/django/forms/models.py +++ b/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] diff --git a/tests/regressiontests/inline_formsets/models.py b/tests/regressiontests/inline_formsets/models.py index c00703852f..8b6f5dd342 100644 --- a/tests/regressiontests/inline_formsets/models.py +++ b/tests/regressiontests/inline_formsets/models.py @@ -51,5 +51,7 @@ Traceback (most recent call last): Exception: has no field named 'test' +# Regression test for #9171. +>>> ifs = inlineformset_factory(Parent, Child, exclude=('school',), fk_name='mother') """ } diff --git a/tests/regressiontests/modeladmin/models.py b/tests/regressiontests/modeladmin/models.py index f7526ab3dd..3a7d3f031f 100644 --- a/tests/regressiontests/modeladmin/models.py +++ b/tests/regressiontests/modeladmin/models.py @@ -123,6 +123,14 @@ displayed because you forgot to add it to fields/fielsets >>> 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`.