1from django.contrib.auth.models import User, Group
2
3group = Group(name="Author")
4group.save() # Create a sample group.
5user = User.objects.get(username="Johndoe") # get Some User.
6user.groups.add(group) # Add User 'Johndoe' to a Group.
7
8# check if user belongs to certain group.
9if user.groups.filter(name=group):
10 # do your stuff and give user access.
11else:
12 # redirect him