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):
|
20 | 20 | ordering = ('name',) |
21 | 21 | filter_horizontal = ('permissions',) |
22 | 22 | |
| 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 | |
23 | 32 | class UserAdmin(admin.ModelAdmin): |
24 | 33 | add_form_template = 'admin/auth/user/add_form.html' |
25 | 34 | change_user_password_template = None |