Skip to content

Instantly share code, notes, and snippets.

@nychng
Created July 2, 2012 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nychng/3033889 to your computer and use it in GitHub Desktop.
Save nychng/3033889 to your computer and use it in GitHub Desktop.
from django.core.management.base import BaseCommand
from django.contrib.auth.models import Group
from events.models import Event
from role.models import Role
class Command(BaseCommand):
"""
This is a one time command that updates an event's general users to groups
"""
def handle(self, *args, **options):
# get AEPA2012
aepa = Event.objects.get(pk=6)
tf = Event.objects.get(pk=2)
# get all the users for aepa and add them to group
aepa_role = Role.objects.get(event=aepa, roletype__name='General')
aepa_group = Group.objects.get(name='%s: Delegate' % aepa.name)
for profile in aepa_role.profiles.all():
profile.user.groups.add(aepa_group)
print profile.user
# get all the users for aepa and add them to group
tf_role = Role.objects.get(event=tf, roletype__name='General')
tf_group = Group.objects.get(name='%s: Delegate' % tf.name)
for profile in tf_role.profiles.all():
profile.user.groups.add(tf_group)
print profile.user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment