Processing file uploads before object is saved

后端 未结 3 1415
情书的邮戳
情书的邮戳 2020-12-30 16:17

I\'ve got a model like this:

class Talk(BaseModel):
  title        = models.CharField(max_length=200)
  mp3          = models.FileField(upload_to = u\'talks/         


        
3条回答
  •  渐次进展
    2020-12-30 17:01

    You can access the file data in request.FILES while in your view.

    I think that best way is to bind uploaded files to a form, override the forms clean method, get the UploadedFile object from cleaned_data, validate it anyway you like, then override the save method and populate your models instance with information about the file and then save it.

提交回复
热议问题