django - Pinax teams - given a user find all the teams for which the user is a member -
i using pinax-teams model teams , memberships. trying see best way find following:
given user, teams member of. have following , inefficient. appreciated. here link pinax-teams https://github.com/pinax/pinax-teams/blob/master/pinax/teams/models.py
team_set = [] user_name = self.request.query_params.get('user_name', none) user = user() if user_name not none: user = user.objects.get(username=user_name) team in team.objects.all(): if team.for_user(user): team_set.append(team) return team_set
there's no need complex or inefficient. can follow relationships in single query:
teams = team.objects.filter(memberships__user=user)
Comments
Post a Comment