How to add a group programatically:
from django.contrib.auth.models import Group
...
# This adds a group to the group list
g = Group()
g.name="foo"
g.save()
# To add the group to a users group list
g = Group.objects.get(name="foo")
u = MyUser.objects.get(username="foo_user")
u.groups.add(g)
u.save()
# see the groups in u
u.groups.all()
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment