Django: Save an uploaded file to a FileField
Posted
by David Wolever
on Stack Overflow
See other posts from Stack Overflow
or by David Wolever
Published on 2010-05-16T18:37:24Z
Indexed on
2010/05/16
18:40 UTC
Read the original article
Hit count: 152
I feel a little stupid for having to ask this… But I can't seem find it documented anywhere.
If I've got a Model
with FileField
, how can I stuff an uploaded FILE
into that FileField
?
For example, I'd like to do something like this:
class MyModel(Model):
file = FileField(...)
def handle_post(request, ...):
mymodel = MyModel.objects.get(...)
if request.FILES.get("newfile"):
mymodel.file = request.FILES["newfile"]
But that doesn't appear to work.
© Stack Overflow or respective owner