Re: Problem when creating a form for adding users to groups
Which one error ?
Many thanks,
Serge
+380 636150445
skype: skhohlov
Serge
+380 636150445
skype: skhohlov
On Tue, Jun 18, 2013 at 1:56 PM, Lucas Lins <lucas.fsl.92@gmail.com> wrote:
Hi.I ran into a problem and have searched the group, in the official django and the internet and could not solve the problem.I created a form that lists all the groups created and all user created and this adds form users within groups.
Already tried two ways and both give errorform.pyclass alterar_usuario(forms.Form):Usuario = forms.ModelMultipleChoiceField(queryset= User.objects.all() )Grupo = forms.ModelMultipleChoiceField(queryset = Group.objects.all())
(way 1)view.pydef cadastrarUsuarioGrupo(request):if request.method == "POST":form = alterar_usuario(request.POST)if form.is_valid():Usuario = form.cleaned_data['Usuario']Grupo = form.cleaned_data['Grupo']
usuarioOb = User.objects.get(id = Usuario)groupOb = Group.objects.get(id = Grupo)usuarioOb.groups.add(groupOb)(way 2)view.pydef cadastrarUsuarioGrupo(request):if request.method == "POST":form = alterar_usuario(request.POST)if form.is_valid():Usuario = form.cleaned_data['Usuario']Grupo = form.cleaned_data['Grupo']usuarioOb = User.objects.filter(id = Usuario)groupOb = Group.objects.filter(id = Grupo)for user, group in usuarioOb, groupOb:user = usuarioOb.usergroup = grupoOb.groupsusuer.groups.add(group)Grateful.--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home