Fixed #12340 -- `BaseGenericInlineFormSet.get_queryset` now returns an ordered queryset.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11800 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
85bfaf1017
commit
81dd5c2473
|
@ -317,10 +317,13 @@ class BaseGenericInlineFormSet(BaseModelFormSet):
|
|||
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.
|
||||
|
|
|
@ -81,6 +81,11 @@ class GenericAdminViewTest(TestCase):
|
|||
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 @@ class GenericInlineAdminParametersTest(TestCase):
|
|||
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.')
|
||||
|
|
Loading…
Reference in New Issue