Ticket #15206: django-15206.patch

File django-15206.patch, 1.3 KB (added by Chris Adams, 14 years ago)
  • django/contrib/auth/admin.py

    From 30b7aae0bf6962034aa836108ab00624d1a197dc Mon Sep 17 00:00:00 2001
    From: Chris Adams <chris@improbable.org>
    Date: Tue, 1 Feb 2011 15:05:34 -0500
    Subject: [PATCH] contrib.auth: use select_related on group change_form
    
    This avoids making a query for each permission loading its content_type
    ---
     django/contrib/auth/admin.py |    9 +++++++++
     1 files changed, 9 insertions(+), 0 deletions(-)
    
    diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
    index 497e9b9..683b0af 100644
    a b class GroupAdmin(admin.ModelAdmin):  
    2020    ordering = ('name',)
    2121    filter_horizontal = ('permissions',)
    2222
     23    def formfield_for_manytomany(self, db_field, request=None, **kwargs):
     24        if db_field.name == "permissions":
     25            qs = kwargs.get("queryset", db_field.rel.to.objects)
     26            # Avoid a major performance hit resolving permission names which
     27            # triggers a content_type load:
     28            kwargs['queryset'] = qs.select_related("content_type")
     29
     30        return super(GroupAdmin, self).formfield_for_manytomany(db_field, request=None, **kwargs)
     31
    2332class UserAdmin(admin.ModelAdmin):
    2433    add_form_template = 'admin/auth/user/add_form.html'
    2534    change_user_password_template = None
Back to Top