django user group check

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

group = Group(name="Author") # 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.
  # redirect him

Here is what the above code is Doing:
1. Create a group called Author.
2. Get a user called Johndoe.
3. Add the user to the group.
4. Check if the user belongs to the group.
5. If the user belongs to the group, do your stuff.
6. If the user doesn’t belong to the group, redirect him.