> Yes, but I won't know the value of 'foo' until runtime. There's no
> other way to set it? I don't want to hardcode a bunch of entries like
> "self.somefield = whatever" in __init__, either, because I'm trying to
> consolidate a bunch of ad-hoc code into a single inheritable class.
Use fields instead of base_fields :
1.
class TestForm(forms.Form):
def __init__(self, *args, **kwargs):
super(ArrivalForm, self).__init__(*args, **kwargs)
self.fields['somefield'].label = 'foo'
somefield = forms.IntegerField()
2.
class TestForm(forms.Form):
def __init__(self, *args, **kwargs):
super(ArrivalForm, self).__init__(*args, **kwargs)
self.fields['somefield'] = forms.IntegerField(label = 'foo')
ArrivalForm in 'super' should be TestForm
second is better eg. if you're using i18n and defining a form and
views in one file.
Because if you use:
ugettext as _
this will work in __init__ but not for a class attribute.
Using ugettext_lazy will work with field defined as a class attribute
but may break some other code in views.
--
Maciej Wisniowski
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---