Code

Ticket #9171: 9171-inlineformset_factory-r9082.2.diff

File 9171-inlineformset_factory-r9082.2.diff, 2.2 KB (added by mrmachine, 6 years ago)

Also fix ModelAdmin and InlineModelAdmin to allow a tuple for exclude.

Line 
1Index: django/forms/models.py
2===================================================================
3--- django/forms/models.py      (revision 9082)
4+++ django/forms/models.py      (working copy)
5@@ -528,6 +528,7 @@
6     if fk.unique:
7         max_num = 1
8     if exclude is not None:
9+        exclude = list(exclude)
10         exclude.append(fk.name)
11     else:
12         exclude = [fk.name]
13Index: django/contrib/admin/options.py
14===================================================================
15--- django/contrib/admin/options.py     (revision 9082)
16+++ django/contrib/admin/options.py     (working copy)
17@@ -266,7 +266,7 @@
18         if self.exclude is None:
19             exclude = []
20         else:
21-            exclude = self.exclude
22+            exclude = list(self.exclude)
23         defaults = {
24             "form": self.form,
25             "fields": fields,
26@@ -780,7 +780,7 @@
27         if self.exclude is None:
28             exclude = []
29         else:
30-            exclude = self.exclude
31+            exclude = list(self.exclude)
32         defaults = {
33             "form": self.form,
34             "formset": self.formset,
35Index: tests/regressiontests/modeladmin/models.py
36===================================================================
37--- tests/regressiontests/modeladmin/models.py  (revision 9082)
38+++ tests/regressiontests/modeladmin/models.py  (working copy)
39@@ -123,7 +123,15 @@
40 >>> ma = BandAdmin(Band, site)
41 >>> ma.get_form(request).base_fields.keys()
42 ['name', 'sign_date']
43+
44+# You can also pass a tuple to `exclude`.
45 
46+>>> class BandAdmin(ModelAdmin):
47+...     exclude = ('bio',)
48+>>> ma = BandAdmin(Band, site)
49+>>> ma.get_form(request).base_fields.keys()
50+['name', 'sign_date']
51+
52 # Using `fields` and `exclude`.
53 
54 >>> class BandAdmin(ModelAdmin):
55Index: tests/regressiontests/inline_formsets/models.py
56===================================================================
57--- tests/regressiontests/inline_formsets/models.py     (revision 9082)
58+++ tests/regressiontests/inline_formsets/models.py     (working copy)
59@@ -51,5 +51,7 @@
60 Exception: <class 'regressiontests.inline_formsets.models.Child'> has no field named 'test'
61 
62 
63+# Regression test for #9171.
64+>>> ifs = inlineformset_factory(Parent, Child, exclude=('school',), fk_name='mother')
65 """
66 }