Django form validation, clean(), and file upload -


can illuminate me when uploaded file written location returned "upload_to" in filefield, in particular regards order of field, model, , form validation , cleaning?

right have "clean" method on model assumes uploaded file in place, can validation on it. looks file isn't yet saved, , may held in temporary location or in memory. if case, how "open" or find path if need execute external process/program validate file?

thanks,

ian

the form cleansing has nothing saving file, or saving other data matter. file isn't saved until run save() method of model instance (note if use modelname.objects.create() save() method called automatically).

the bound form contain open file object, should able validation on object directly. example:

form = myform(request.post, request.files) if form.is_valid():     file_object = form.cleaned_data['myfile']     #run validation on file_object, or define clean_myfile() method      #  run automatically when call form.is_valid()      model_inst = mymodel('my_file' = file_object,                      #assign other attributes here....                      )     model_inst.save() #file saved disk here 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -