Figured it out.

Just like Kenneth said above, I need a super line where he said.  I
was also appending the values incorrectly.  It should have been

GROUP_CHOICES += ((g.id, g.name),)

Thanks for the help everyone.

On Jan 12, 11:14 am, ocgstyles <[EMAIL PROTECTED]> wrote:
> Great.  That works.  Only problem now, though, is that GROUP_CHOICES
> is still [] after the object is instantiated.  From a shell I can do
> this:
>
> f = ReferralForm(User.objects.get(username='keith'))
> f.fields['field1'].choices = f.GROUP_CHOICES
>
> And that will populate the field with the right data.  How do I do
> this in the class itself?
>
> Keith
>
> On Jan 12, 6:25 am, shabda <[EMAIL PROTECTED]> wrote:
>
> > Instead of this
> >    def __init__(self, user):
> >       profile = user.get_profile()
>
> >       for g in profile.groups.all():
> >          self.GROUP_CHOICES += (g.id, g.name)
>
> >       super(MyForm, self)
>
> > Should it not be,
> >    def __init__(self, user, *args, **kwargs):
> >       profile = user.get_profile()
>
> >       for g in profile.groups.all():
> >          self.GROUP_CHOICES += (g.id, g.name)
>
> >       super(MyForm, self).__init__(*args, **kwargs)
>
> > On Jan 12, 2:18 pm, ocgstyles <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
>
> > > I using the newforms library to create a form.  I need to know who the
> > > current user is so I know which values to display in a dropdown
> > > control.  So I have this so far:
>
> > > from django import newforms as forms
>
> > > class MyForm(forms.Form):
> > >     GROUP_CHOICES = []
>
> > >    field1 = forms.ChoiceField(choices=GROUP_CHOICES)
> > >    field2 = forms.CharField(widget=forms.Textarea())
>
> > >    def __init__(self, user):
> > >       profile = user.get_profile()
>
> > >       for g in profile.groups.all():
> > >          self.GROUP_CHOICES += (g.id, g.name)
>
> > >       super(MyForm, self)
>
> > > But when I try to render this in the template
> > > (  {{ form.as_table }} ), I get no output.  Am I creating this form
> > > class incorrectly?
>
> > > Keith
--~--~---------~--~----~------------~-------~--~----~
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