On 03/04/07, TaMeR <[EMAIL PROTECTED]> wrote:
>
>
> I use two registration forms one for clients one for vendors.
> Depending on form used I would like to assign the user to a group.
>
> How do I use new_user.groups.add('Client')
>
> Below is my code that does not raise any errors but also does not add
> the user to the group.
>
> =====  CODE =====
> def register(request, success_url='/accounts/register/complete/'):
>
>     Context::
>         form
>             The registration form
>
>     Template::
>         registration/registration_form.html
>
>     """
>     if request.method == 'POST':
>         form = RegistrationForm(request.POST)
>         if form.is_valid():
>             new_user 
> =RegistrationProfile.objects.create_inactive_user(username=form.clean_data['username'],
>
> password=form.clean_data['password1'],
>
> email=form.clean_data['email'])
>             new_user.groups.add('Client')
>             return HttpResponseRedirect(success_url)
>     else:
>         form = RegistrationForm()
>     return render_to_response('registration/registration_form.html',
>                               { 'form': form },
>                               context_instance=RequestContext(request)
>                              )
>
>

If i remember correctly, .add() takes an object that it needs
association to, so you'll have to do (where condition expresses which
group you want to add the user to):

group  = Group.objects.get(condition)
new_user.groups.add(group)

I'm not sure why it doesn't raise errors there though, if .add() only
accepts a related object.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to