Hello,

I am trying to implement a ChoiceField that's choices shall be
calculated during form instantiation in the view depending on the
users preferred language (according to request.LANGUAGE_CODE from
LocaleMiddleware).

Example forms.py:
CHOICES = zip(
    [x.number for x in MyModel.objects.all()],
    [x.locale.get(lang=request.LANGUAGE_CODE).name for x in
MyModel.objects.all()]
)
#locale is the manager from an generic relation (http://
docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1)

MyForm(forms.Form):
    myfield = forms.ChoiceField(choices=CHOICES)


This of course doesn't work (NameError, request is not defined). I've
also played around with the LazyChoiceField I've found here <http://
www.djangosnippets.org/snippets/1767/>, but couldn't manage it to
work. I think I somehow need to define a dummy request that is later
replaced with the "real" request. But how do I do that?

Thanks for help,
Andreas
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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