I have a form like this:
class MyForm(forms.Form):
[...]
which is rendered in my view:
if request.method == 'GET':
form = MyForm(request.GET)
Now, i want to add a form field which contains a set of values in a select-field, and the queryset must be filtered by the currently logged in user. So I changed the method signature so that it contains the request-object:
class MyForm(forms.Form):
def __init__(self, user, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.myfield = forms.ChoiceField([('%s' % d.id, '%s' % d.name) for d in MyModel.objects.filter(owners = user)])
but all I get after rendering the form is an object-reference as string instead of the select-widget. I seems that a form field, once declared, can not be modified.
Any ideas?