Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@jbronn jbronn authored
View
5 django/contrib/contenttypes/generic.py
@@ -317,10 +317,13 @@ def get_queryset(self):
from django.contrib.contenttypes.models import ContentType
if self.instance is None or self.instance.pk is None:
return self.model._default_manager.none()
- return self.model._default_manager.filter(**{
+ qs = self.model._default_manager.filter(**{
self.ct_field.name: ContentType.objects.get_for_model(self.instance),
self.ct_fk_field.name: self.instance.pk,
})
+ if not qs.ordered:
+ qs = qs.order_by(self.model._meta.pk.name)
+ return qs
def save_new(self, form, commit=True):
# Avoid a circular import.
View
7 tests/regressiontests/generic_inline_admin/tests.py
@@ -81,6 +81,11 @@ def testGenericInlineFormsetFactory(self):
inline_formset = generic_inlineformset_factory(Media,
exclude=('url',))
+ # Regression test for #12340.
+ e = Episode.objects.get(name='This Week in Django')
+ formset = inline_formset(instance=e)
+ self.failUnless(formset.get_queryset().ordered)
+
class GenericInlineAdminParametersTest(TestCase):
fixtures = ['users.xml']
@@ -139,4 +144,4 @@ def testExcludeParam(self):
e = self._create_object(EpisodeExclude)
response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episodeexclude/%s/' % e.pk)
formset = response.context['inline_admin_formsets'][0].formset
- self.failIf('url' in formset.forms[0], 'The formset has excluded "url" field.')
+ self.failIf('url' in formset.forms[0], 'The formset has excluded "url" field.')
Please sign in to comment.
Something went wrong with that request. Please try again.