Fixed #10163: add an artificial ordering to querysets used by formsets, thus ensuring that POSTed data "lines up" correctly every time. Thanks to Karen Tracey for pointing in the right direction here.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10625 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2009-04-22 22:16:42 +00:00
parent 855a58f963
commit 9ea2198fd1
1 changed files with 7 additions and 0 deletions

View File

@ -406,6 +406,13 @@ class BaseModelFormSet(BaseFormSet):
qs = self.queryset qs = self.queryset
else: else:
qs = self.model._default_manager.get_query_set() qs = self.model._default_manager.get_query_set()
# If the queryset isn't already ordered we need to add an
# artificial ordering here to make sure that all formsets
# constructed from this queryset have the same form order.
if not qs.ordered:
qs = qs.order_by(self.model._meta.pk.name)
if self.max_num > 0: if self.max_num > 0:
self._queryset = qs[:self.max_num] self._queryset = qs[:self.max_num]
else: else: