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