Hi Tom, What do you mean callable? I tried changing desig_group = forms.ChoiceField(choices=choice_desig()) to desig_group = forms.ChoiceField(choices=choice_desig)
It gave error 'function' object is not iterable. But I want to know if the following would work. desig = forms.ModelChoiceField(queryset=Group.objects.all()) But how do I change my view and template for it. Can you please correct my view and template. Regards, Preetam On Wednesday, 19 March 2014 21:43:39 UTC+5:30, Tom Evans wrote: > > On Wed, Mar 19, 2014 at 3:40 PM, sashank reddy > <preetamsa...@gmail.com <javascript:>> wrote: > > Hi, > > > > I have been trying to extend the UserCreationForm and have a form which > > performs user registration and adds email and the names. > > In addition I am using a choice field that allows a list down of > existing > > groups so that you can assign the user to an group immediately upon > > creation. > > > > The problem is that, if I create a new group, and try to add users to > it, > > then the form validation fails. > > I have restart the django server or wait for it to reset internally and > show > > "Validating models ..". Then it starts to work. > > > > The following is the code snippet: > > > ============================================================================= > > > def choice_desig(): > > choice_desig = [] > > g = Group.objects.all() > > for k in g: > > choice_desig.append((k.name, k.name)) > > return choice_desig > > > > class New_user_form(UserCreationForm): > > email = forms.EmailField(required=True) > > first_name = forms.CharField(required=True) > > last_name = forms.CharField(required=True) > > desig_group = forms.ChoiceField(choices=choice_desig()) > > If you use choice_desig() function like that, it will get called once, > when the server initially parses that file. It will never be run again > until the server re-parses that file. > > You could pass a callable to choices - "choices=choice_desig". > > However, the right solution for when you want a form field to choose a > model instance is to use a form.ModelChoiceField. > > Cheers > > Tom > -- 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+unsubscr...@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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/37f3f382-7cdd-4331-8fd5-174ec5713cd1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.