Hello,
I'm using the following to provide a select box with filtered choices:
class AssetForm(ModelForm):
"""Asset form takes a project id. It only allows workstreams
attached to
this project name."""
workstreams = forms.ModelChoiceField(Workstream, None)
def __init__(self, *args, **kwargs):
super(AssetForm, self).__init__(*args, **kwargs)
if self.instance:
self.fields['workstreams'].queryset =
Workstream.objects.filter(project__id=args[0])
self.fields['workstreams'].widget.choices =
self.base_fields['workstreams'].choices
I instantiate it
f = AssetForm(1) # 1 is the number of a project, which I filter with.
It seems to work, and I can poke around at the fields and choices.
but when I try to render it:
f.as_p()
I get:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "django\django\forms\forms.py", line 191, in as_p
return self._html_output(u'<p>%(label)s %(field)s%(help_text)s</
p>', u'%s',
'</p>', u' %s', True)
File "django\django\forms\forms.py", line 139, in _html_output
top_errors = self.non_field_errors() # Errors that should be
displayed above
all fields.
File "django\django\forms\forms.py", line 199, in non_field_errors
return self.errors.get(NON_FIELD_ERRORS, self.error_class())
File "django\djang
o\forms\forms.py", line 111, in _get_errors
self.full_clean()
File "django\django\forms\forms.py", line 218, in full_clean
value = field.widget.value_from_datadict(self.data, self.files,
self.add_pre
fix(name))
File "django\django\forms\widgets.py", line 170, in
value_from_datadict
return data.get(name, None)
AttributeError: 'int' object has no attribute 'get'
Any ideas?
Thanks,
Justin
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---