=== modified file 'django/forms/formsets.py'
|
|
|
170 | 170 | return x[1] - y[1] |
171 | 171 | self._ordering.append((i, form.cleaned_data[ORDERING_FIELD_NAME])) |
172 | 172 | # After we're done populating self._ordering, sort it. |
173 | | self._ordering.sort(compare_ordering_values) |
| 173 | if self._ordering: |
| 174 | self._ordering.sort(compare_ordering_values) |
174 | 175 | # Return a list of form.cleaned_data dicts in the order spcified by |
175 | 176 | # the form data. |
176 | 177 | return [self.forms[i[0]] for i in self._ordering] |
=== modified file 'tests/regressiontests/forms/formsets.py'
|
|
|
366 | 366 | {'votes': 500, 'ORDER': None, 'choice': u'The Decemberists'} |
367 | 367 | {'votes': 50, 'ORDER': None, 'choice': u'Basia Bulat'} |
368 | 368 | |
| 369 | Ordering should work with blank fieldsets. |
| 370 | |
| 371 | >>> data = { |
| 372 | ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered |
| 373 | ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data |
| 374 | ... } |
| 375 | |
| 376 | >>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
| 377 | >>> formset.is_valid() |
| 378 | True |
| 379 | >>> for form in formset.ordered_forms: |
| 380 | ... print form.cleaned_data |
369 | 381 | |
370 | 382 | # FormSets with ordering + deletion ########################################### |
371 | 383 | |