Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12340 -- `BaseGenericInlineFormSet.get_queryset` now returns a…

…n ordered queryset.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11800 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 81dd5c247366986339c9c22c058e8b0864392cd1 1 parent 85bfaf1
Justin Bronn authored December 09, 2009
5  django/contrib/contenttypes/generic.py
@@ -317,10 +317,13 @@ def get_queryset(self):
317 317
         from django.contrib.contenttypes.models import ContentType
318 318
         if self.instance is None or self.instance.pk is None:
319 319
             return self.model._default_manager.none()
320  
-        return self.model._default_manager.filter(**{
  320
+        qs = self.model._default_manager.filter(**{
321 321
             self.ct_field.name: ContentType.objects.get_for_model(self.instance),
322 322
             self.ct_fk_field.name: self.instance.pk,
323 323
         })
  324
+        if not qs.ordered:
  325
+            qs = qs.order_by(self.model._meta.pk.name)
  326
+        return qs
324 327
 
325 328
     def save_new(self, form, commit=True):
326 329
         # Avoid a circular import.
7  tests/regressiontests/generic_inline_admin/tests.py
@@ -81,6 +81,11 @@ def testGenericInlineFormsetFactory(self):
81 81
         inline_formset = generic_inlineformset_factory(Media,
82 82
             exclude=('url',))
83 83
 
  84
+        # Regression test for #12340.
  85
+        e = Episode.objects.get(name='This Week in Django')
  86
+        formset = inline_formset(instance=e)
  87
+        self.failUnless(formset.get_queryset().ordered)
  88
+
84 89
 class GenericInlineAdminParametersTest(TestCase):
85 90
     fixtures = ['users.xml']
86 91
 
@@ -139,4 +144,4 @@ def testExcludeParam(self):
139 144
         e = self._create_object(EpisodeExclude)
140 145
         response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episodeexclude/%s/' % e.pk)
141 146
         formset = response.context['inline_admin_formsets'][0].formset
142  
-        self.failIf('url' in formset.forms[0], 'The formset has excluded "url" field.')
  147
+        self.failIf('url' in formset.forms[0], 'The formset has excluded "url" field.')

0 notes on commit 81dd5c2

Please sign in to comment.
Something went wrong with that request. Please try again.