I am trying to upload a file using the newforms library. So far from
reading other posts and googling around it appears I have to copy the
request.POST dictionary and update it with request.FILES. Then I
would do a "model.save_<fieldname>_file(<filename>, <content>)" to
actually save the file.
Here's the code where I try to do this:
AddDataFormClass = forms.form_for_model(Data)
form_data = request.POST.copy()
form_data.update(request.FILES)
newform = AddDataFormClass(form_data)
if newform.is_valid():
newdata = Data()
newdata.experiment = newform.clean_data['experiment']
newdata.data_owner = newform.clean_data['data_owner']
newdata.label = newform.clean_data['label']
newdata.save() # is this needed?
newdata.save_data_file_file(newform['data_file']
['filename'],
newform['data_file']['content'])
In my model I have a "data_file" field. What I am not sure if
newdata.save() is actually required. But nonetheless when I try to
save a file I get the following error:
'BoundField' object is unsubscriptable
The line where it results in this error is
newdata.save_data_file_file(newform['data_file']
['filename'],
newform['data_file']['content'])
So there is something Django doesn't like about this line. Can
someone tell me what I'm doing wrong?
Thanks,
Jonathan.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---