Skip to content

Commit

Permalink
Reduced number of SQL queries on item admin page (see #237)
Browse files Browse the repository at this point in the history
  • Loading branch information
idlesign committed Sep 19, 2017
1 parent 56b4066 commit 80e5cec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ django-sitetree changelog
=========================


Unreleased
----------
* Reduced number of SQL queries on item admin page (see #237)


v1.8.0
------
+ IMPORTANT: i18n trees now support full lang names (e.g. de-ch, pt-br), update your i18n trees aliases.
Expand Down
11 changes: 11 additions & 0 deletions sitetree/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ class TreeItemAdmin(admin.ModelAdmin):
change_form_template = 'admin/sitetree/treeitem/change_form.html'
delete_confirmation_template = 'admin/sitetree/treeitem/delete_confirmation.html'

def formfield_for_manytomany(self, db_field, request=None, **kwargs):

# The same as for GroupAdmin
# Avoid a major performance hit resolving permission names which
# triggers a content_type load:
if db_field.name == 'access_permissions':
qs = kwargs.get('queryset', db_field.remote_field.model.objects)
kwargs['queryset'] = qs.select_related('content_type')

return super(TreeItemAdmin, self).formfield_for_manytomany(db_field, request=request, **kwargs)

def response_add(self, request, obj, post_url_continue=None, **kwargs):
"""Redirects to the appropriate items' 'continue' page on item add.
Expand Down

0 comments on commit 80e5cec

Please sign in to comment.