I am trying to upload a file from a shell to one of my django models in the following manner:
a = Post(name=name, content=content)
a.attachment.save('some.pdf', File(open('some.pdf', 'r')))
But I keep getting the following error:
TypeError: must be convertible to a buffer, not FieldFile. I looked at other posts and could not find any solution that solves this problem.
I am using Python 2.7 and Django 1.10. I would really appreciate any help.
EDIT: The problem was not with the way I was storing the file but was with my post-save signals. Sorry and thanks for your help!
try:
f = open('some.pdf', 'r')
a.attachment = File(f)
a.save()
f.close()