I have choiceField
to create a select box with some options. Something like that:
forms.py class NewForm(forms.Form): title = forms.CharField(max_length=69) parent = forms.ChoiceField(choices = CHOICE)
But I want to be able to create parameters without having a predefined tuple (which is required by choiceField
). Basically, I need to have access to request.user to populate some parameter tags according to each user, but I don't know if there is a way to use the request in form classes. Form.
An alternative would be to preinstall an instance of NewForm
with:
views.py form = NewForm(initial={'choices': my_actual_choices})
but I have to add a dummy CHOICE method to create a NewForm, and my_actual_choices doesn't seem to work.
I think the third way to solve this is to subclass ChoiceField and override save()
, but I'm not sure how to do it.
source share