Skip to content

Instantly share code, notes, and snippets.

@SmileyChris
Forked from mekhami/context_processors.py
Last active August 4, 2016 22:05
Show Gist options
  • Save SmileyChris/7205e645237df5632a183b6bdff2c26a to your computer and use it in GitHub Desktop.
Save SmileyChris/7205e645237df5632a183b6bdff2c26a to your computer and use it in GitHub Desktop.
def user_in_group(user, group_id=None, group_id_list=None):
if group_id_list is None:
group_id_list = set(group_id]
if not hasattr(user, 'group_ids'):
user.group_ids = set(user.groups.values_list('pk', flat=True))
return user.group_ids.intersection(group_id_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment