Code

Ticket #8899: 8899.exclude-tuple.diff

File 8899.exclude-tuple.diff, 1.8 KB (added by julien, 6 years ago)

patch + tests

Line 
1Index: django/django/contrib/admin/options.py
2===================================================================
3--- django/django/contrib/admin/options.py      (revision 9070)
4+++ django/django/contrib/admin/options.py      (working copy)
5@@ -270,7 +270,7 @@
6         defaults = {
7             "form": self.form,
8             "fields": fields,
9-            "exclude": exclude + kwargs.get("exclude", []),
10+            "exclude": list(exclude) + list(kwargs.get("exclude", [])),
11             "formfield_callback": self.formfield_for_dbfield,
12         }
13         defaults.update(kwargs)
14@@ -786,7 +786,7 @@
15             "formset": self.formset,
16             "fk_name": self.fk_name,
17             "fields": fields,
18-            "exclude": exclude + kwargs.get("exclude", []),
19+            "exclude": list(exclude) + list(kwargs.get("exclude", [])),
20             "formfield_callback": self.formfield_for_dbfield,
21             "extra": self.extra,
22             "max_num": self.max_num,
23Index: django/tests/regressiontests/modeladmin/models.py
24===================================================================
25--- django/tests/regressiontests/modeladmin/models.py   (revision 9070)
26+++ django/tests/regressiontests/modeladmin/models.py   (working copy)
27@@ -116,14 +116,22 @@
28 ['name']
29 
30 
31-# Using `exclude`.
32+# Using `exclude` as list.
33 
34 >>> class BandAdmin(ModelAdmin):
35 ...     exclude = ['bio']
36 >>> ma = BandAdmin(Band, site)
37 >>> ma.get_form(request).base_fields.keys()
38 ['name', 'sign_date']
39-
40+
41+# Using `exclude` as tuple.
42+
43+>>> class BandAdmin(ModelAdmin):
44+...     exclude = ('bio',)
45+>>> ma = BandAdmin(Band, site)
46+>>> ma.get_form(request).base_fields.keys()
47+['name', 'sign_date']
48+
49 # Using `fields` and `exclude`.
50 
51 >>> class BandAdmin(ModelAdmin):