Skip to content

Instantly share code, notes, and snippets.

@lane-eb
Created September 30, 2020 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lane-eb/40241696ab4d0819944d9bb8b30d79c7 to your computer and use it in GitHub Desktop.
Save lane-eb/40241696ab4d0819944d9bb8b30d79c7 to your computer and use it in GitHub Desktop.
Django query solution to replace `values_list('repo__name')`.
# IMO, This is the best.
def contributor_repo_names(self, organization):
repo_ids = Commit.objects.filter(
repo__in=organization.repos.all(),
committer=self
).values_list('repo_id', flat=True).distinct('repo_id')
return list(
GitRepo.objects.filter(repo_id__in=repo_ids).values_list('name', flat=True)
)
# IMO, This is not as good as the previous one.
def contributor_repo_names(self, organization):
return list(Commit.objects.filter(repo__in=organization.repos.all(),
committer=self)
.values_list('repo__name', flat=True).distinct('repo_id'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment