Hi Daniel,

This has got me closer but i'm now just getting an empty select box
appearing on in the form, with no data in.

class NewBugForm(forms.Form):
  assigned_to = forms.CharField(max_length=50,widget=forms.Select
(choices=[]), initial='Anyone',required=False)

  def __init__(self, *args, **kwargs):
      all_users = kwargs.pop("all_users")
      super(NewBugForm, self).__init__(*args,**kwargs)
      print all_users
      self.fields['assigned_to'].choices = all_users


If I print out all_users I can see it is there after the super(), but
for some reason its not appending to the form. The following is a
print out of all_users:

(('Anyone', 'Anyone'), ('Pete Randall', 'Pete Randall'), ('Chris
Smith', 'Chris Smith'))

Could it have something to do with that list not being in the right
format?

Cheers,

Pete.

On Feb 20, 10:47 am, Daniel Roseman <roseman.dan...@googlemail.com>
wrote:
> On Feb 20, 9:01 am, pete <pet...@gmail.com> wrote:
>
>
>
> > Hi Malcolm, thanks for the reply.
>
> > I've tried it with the fields indented like so:
> >  http://dpaste.com/122916/
>
> > I've commented out the browser choices and status fields etc to keep
> > the amount of code down for the moment.
>
> > I now get an error that assigned_to (line15) doesn't think that the
> > variable all_users exists. If i then comment out assigned_to the rest
> > of the form will display.
>
> > So my issue is how do I pass 'all_users' from the __init__ method to
> > the form field lower down? Or should it be that the __init__ method
> > initialises the form with that variable then when super() is called it
> > build the form?
>
> Don't do it that way. Do it like this:
>
> class NewBugForm(forms.Form):
>     (...other fields...)
>     assigned_to = forms.CharField(max_length=50,
>           widget=forms.Select(choices=[]), initial='Anyone',
> required=False)
>
>     def __init__(self, *args, **kwargs):
>         all_users = kwargs.pop("all_users")
>         super(NewBugForm, self).__init__(*args,**kwargs)
>         self.fields['assigned_to'].choices = all_users
>
> --
> DR.

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to