Answers for "how to get current user group name in django"

3

django user group check

from django.contrib.auth.models import User, Group

group = Group(name="Author")
group.save() # Create a sample group.
user = User.objects.get(username="Johndoe") # get Some User.
user.groups.add(group) # Add User 'Johndoe' to a Group.

# check if user belongs to certain group.
if user.groups.filter(name=group):
  # do your stuff and give user access.
else:
  # redirect him
Posted by: Guest on October-13-2020
0

django get group users

users = User.objects.filter(groups_name='group_name')
Posted by: Guest on October-06-2021

Code answers related to "how to get current user group name in django"

Python Answers by Framework

Browse Popular Code Answers by Language