i have django view communicate user's preferred locale form in forms.py. however, form seems initialized before call it.
class surveyform() seems load before call views.py , before surveyforms() init function becomes active.
here code:
class surveyform(forms.form): questions = question.objects.all() q1 = questions.get(identifier='q1') question1 = forms.charfield(required=false, label=q1.name) def __init__(self, *args, **kwargs): translation.activate('nl')
when put translation.activate('nl')
in surveyform
class, work. when put translation.activate('nl')
in __init__
, or in views.py
, not work. how can changed?
note: use modeltranslation, q1.name
dutch translation when dutch language active.
anything @ class level executed when class defined, on first import. know how things @ instantation time - doing in __init__
method.
it's not clear question q1
is. field? if can add self.fields
; otherwise set directly on self
.
def __init__(self, *args, **kwargs): translation.activate('nl') super(surveyform, self).__init__(*args, **kwargs) self.fields['q1'] = ... # or self.q1 = ...
Comments
Post a Comment