Re: newform: Why Doesn't This work
Aaargh...the indentation got screwed up. Here's another attempt: class myForm(forms.Form): def __init__(self, *args, **kwargs): self.q_prime = [] # default choices here? try: self.q_prime = kwargs.pop('q') except: pass super(myForm, self).__init__(*args, **kwargs) self.fields['choice'] = forms.ChoiceField(label="My choice", choices=myChoice(self.q_prime).choices()) #I --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: newform: Why Doesn't This work
class myForm(forms.Form): def __init__(self, *args, **kwargs): try: self.q_prime = kwargs.pop('q') except: pass super(myForm, self).__init__(*args, **kwargs) choice = forms.ChoiceField(label="My choice", choices=myChoice(self.q_prime).choices()) #I As Joe says above, the choice field is a class-level field whereas "self.*" is instance level. So, this doesn't work. Try this instead: class myForm(forms.Form): def __init__(self, *args, **kwargs): self.q_prime = [] # default choices here? try: self.q_prime = kwargs.pop('q') except: pass super(myForm, self).__init__(*args, **kwargs) self.fields['choice'] = forms.ChoiceField(label="My choice", choices=myChoice(self.q_prime).choices()) #I Note the indentation of that last line -- it now belongs to the __init__ method and not to the class. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: newform: Why Doesn't This work
The "choice = " is getting evaluated as a class, and the self.q_prime is referring to an instance of the class myForm. At least I think that's what's happening here... -joe On 10/16/07, johnny <[EMAIL PROTECTED]> wrote: > > Below is my form class. Inside myForm, I tried doing this: > > choice = forms.ChoiceField(label="My choice", >choices=myChoice(self.q_prime).choices()) > > I get an error right here "choices=myChoice(self.q_prime).choices()": > name 'self' is not defined > > My Form Class: > > class myChoice: > def __init__(self, q_prime): > _choice = [] > #_choice.append(q_prime) > > def choices(): > _choice.append("yellow") > _choice.append("red") > > return _choice > > class myForm(forms.Form): > def __init__(self, *args, **kwargs): > try: > self.q_prime = kwargs.pop('q') > except: > pass > super(myForm, self).__init__(*args, **kwargs) > > choice = forms.ChoiceField(label="My choice", >choices=myChoice(self.q_prime).choices()) #I > get an error right here: name 'self' is not defined > > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---