summaryrefslogtreecommitdiff
path: root/django/forms/models.py
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-04-22 22:16:42 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-04-22 22:16:42 +0000
commit9ea2198fd1f2d0abf55373d8175dbb03f7440576 (patch)
treeb81f2ec5a86014576b75b740923498de864922d2 /django/forms/models.py
parent855a58f963bb2aa8eeea14be8f22b14020266d08 (diff)
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
Diffstat (limited to 'django/forms/models.py')
-rw-r--r--django/forms/models.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index 626e727e3a..41380f21e9 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -406,6 +406,13 @@ class BaseModelFormSet(BaseFormSet):
qs = self.queryset
else:
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:
self._queryset = qs[:self.max_num]
else: