Code

Ticket #6953: 6953.diff

File 6953.diff, 7.0 KB (added by dgouldin, 6 years ago)
Line 
1Index: django/forms/models.py
2===================================================================
3--- django/forms/models.py      (revision 8992)
4+++ django/forms/models.py      (working copy)
5@@ -134,10 +134,12 @@
6     fields will be excluded from the returned fields, even if they are listed
7     in the ``fields`` argument.
8     """
9-    # TODO: if fields is provided, it would be nice to return fields in that order
10+
11     field_list = []
12     opts = model._meta
13-    for f in opts.fields + opts.many_to_many:
14+    model_fields = opts.fields + opts.many_to_many
15+    model_fields.sort()
16+    for f in model_fields:
17         if not f.editable:
18             continue
19         if fields and not f.name in fields:
20Index: tests/modeltests/model_forms/models.py
21===================================================================
22--- tests/modeltests/model_forms/models.py      (revision 8992)
23+++ tests/modeltests/model_forms/models.py      (working copy)
24@@ -236,7 +236,7 @@
25 OddForm is now an Article-related thing, because BadForm.Meta overrides
26 CategoryForm.Meta.
27 >>> OddForm.base_fields.keys()
28-['headline', 'slug', 'pub_date', 'writer', 'article', 'status', 'categories']
29+['headline', 'slug', 'pub_date', 'writer', 'article', 'categories', 'status']
30 
31 >>> class ArticleForm(ModelForm):
32 ...     class Meta:
33@@ -247,7 +247,7 @@
34 >>> class BadForm(ArticleForm, CategoryForm):
35 ...     pass
36 >>> OddForm.base_fields.keys()
37-['headline', 'slug', 'pub_date', 'writer', 'article', 'status', 'categories']
38+['headline', 'slug', 'pub_date', 'writer', 'article', 'categories', 'status']
39 
40 Subclassing without specifying a Meta on the class will use the parent's Meta
41 (or the first parent in the MRO if there are multiple parent classes).
42@@ -398,17 +398,17 @@
43 <option value="2">Bob Woodward</option>
44 </select></td></tr>
45 <tr><th>Article:</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr>
46+<tr><th>Categories:</th><td><select multiple="multiple" name="categories">
47+<option value="1">Entertainment</option>
48+<option value="2">It&#39;s a test</option>
49+<option value="3">Third test</option>
50+</select><br /> Hold down "Control", or "Command" on a Mac, to select more than one.</td></tr>
51 <tr><th>Status:</th><td><select name="status">
52 <option value="" selected="selected">---------</option>
53 <option value="1">Draft</option>
54 <option value="2">Pending</option>
55 <option value="3">Live</option>
56 </select></td></tr>
57-<tr><th>Categories:</th><td><select multiple="multiple" name="categories">
58-<option value="1">Entertainment</option>
59-<option value="2">It&#39;s a test</option>
60-<option value="3">Third test</option>
61-</select><br /> Hold down "Control", or "Command" on a Mac, to select more than one.</td></tr>
62 
63 You can restrict a form to a subset of the complete list of fields
64 by providing a 'fields' argument. If you try to save a
65@@ -453,17 +453,17 @@
66 <option value="2">Bob Woodward</option>
67 </select></li>
68 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
69+<li>Categories: <select multiple="multiple" name="categories">
70+<option value="1">Entertainment</option>
71+<option value="2">It&#39;s a test</option>
72+<option value="3">Third test</option>
73+</select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
74 <li>Status: <select name="status">
75 <option value="" selected="selected">---------</option>
76 <option value="1">Draft</option>
77 <option value="2">Pending</option>
78 <option value="3">Live</option>
79 </select></li>
80-<li>Categories: <select multiple="multiple" name="categories">
81-<option value="1">Entertainment</option>
82-<option value="2">It&#39;s a test</option>
83-<option value="3">Third test</option>
84-</select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
85 >>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': u'1', 'article': 'Hello.'}, instance=art)
86 >>> f.is_valid()
87 True
88@@ -514,17 +514,17 @@
89 <option value="2">Bob Woodward</option>
90 </select></li>
91 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
92+<li>Categories: <select multiple="multiple" name="categories">
93+<option value="1" selected="selected">Entertainment</option>
94+<option value="2">It&#39;s a test</option>
95+<option value="3">Third test</option>
96+</select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
97 <li>Status: <select name="status">
98 <option value="" selected="selected">---------</option>
99 <option value="1">Draft</option>
100 <option value="2">Pending</option>
101 <option value="3">Live</option>
102 </select></li>
103-<li>Categories: <select multiple="multiple" name="categories">
104-<option value="1" selected="selected">Entertainment</option>
105-<option value="2">It&#39;s a test</option>
106-<option value="3">Third test</option>
107-</select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
108 
109 >>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04',
110 ...     'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art)
111@@ -630,17 +630,17 @@
112 <option value="2">Bob Woodward</option>
113 </select></li>
114 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
115+<li>Categories: <select multiple="multiple" name="categories">
116+<option value="1">Entertainment</option>
117+<option value="2">It&#39;s a test</option>
118+<option value="3">Third</option>
119+</select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
120 <li>Status: <select name="status">
121 <option value="" selected="selected">---------</option>
122 <option value="1">Draft</option>
123 <option value="2">Pending</option>
124 <option value="3">Live</option>
125 </select></li>
126-<li>Categories: <select multiple="multiple" name="categories">
127-<option value="1">Entertainment</option>
128-<option value="2">It&#39;s a test</option>
129-<option value="3">Third</option>
130-</select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
131 >>> Category.objects.create(name='Fourth', url='4th')
132 <Category: Fourth>
133 >>> Writer.objects.create(name='Carl Bernstein')
134@@ -656,18 +656,18 @@
135 <option value="3">Carl Bernstein</option>
136 </select></li>
137 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
138+<li>Categories: <select multiple="multiple" name="categories">
139+<option value="1">Entertainment</option>
140+<option value="2">It&#39;s a test</option>
141+<option value="3">Third</option>
142+<option value="4">Fourth</option>
143+</select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
144 <li>Status: <select name="status">
145 <option value="" selected="selected">---------</option>
146 <option value="1">Draft</option>
147 <option value="2">Pending</option>
148 <option value="3">Live</option>
149 </select></li>
150-<li>Categories: <select multiple="multiple" name="categories">
151-<option value="1">Entertainment</option>
152-<option value="2">It&#39;s a test</option>
153-<option value="3">Third</option>
154-<option value="4">Fourth</option>
155-</select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
156 
157 # ModelChoiceField ############################################################
158