Django: Save an uploaded file to a FileField -


I'm a bit stupid to ask ... but I think it can not be documented anywhere is.

If I have model with FileField , then I get that FILE in that file FileField ?

For example, I want 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 It does not appear to work.

Good, my suspicion was confirmed: I'm a stupid :)

The outline in my question is, in fact, correct - it was not working because I did not work on enctype = "multipart / form-data" / code> form.

Anyway, I will leave this question here, just root it to others, that is the only problem.


Comments