Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
Added automatic select_related on OrganisationRole
Browse files Browse the repository at this point in the history
  • Loading branch information
reinout committed Nov 13, 2015
1 parent e5265c0 commit 4ba982e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ Changelog of lizard-auth-server
essential for getting permissions right.
[reinout]

- OrganisationRole has a manager now that automatically sets
``select_related()`` to select roles, portals and organisations. Otherwise
to have to add select_related in way too many places. (Uncovered by testing
with the django debug toolbar).
[reinout]


1.2 (2015-11-02)
----------------
Expand Down
11 changes: 11 additions & 0 deletions lizard_auth_server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,15 @@ def as_dict(self):
'unique_id': self.unique_id
}

class OrganisationRoleManager(models.Manager):

def get_queryset(self):
# Always use select_related on role and organisation, otherwise we
# have to specify it in a *lot* of places.
return super(OrganisationRoleManager, self).get_queryset(
).select_related(
'role', 'organisation', 'role__portal')


class OrganisationRole(models.Model):
organisation = models.ForeignKey(
Expand All @@ -670,6 +679,8 @@ class OrganisationRole(models.Model):
verbose_name=_('for all users'),
default=False)

objects = OrganisationRoleManager()

class Meta:
unique_together = (('organisation', 'role'), )
verbose_name = _('organisation-role-mapping')
Expand Down

0 comments on commit 4ba982e

Please sign in to comment.