2020
09-24
09-24
Django 删除upload_to文件的步骤
新版Django在admin后台直接删除一条数据时,file=models.FileField(upload_to=‘file')上传的文件并不会删除,以下为解决方法:在model.py加入:fromdjango.db.models.signalsimportpre_deletefromdjango.dispatch.dispatcherimportreceiver@receiver(pre_delete,sender=AddDateModel)defmymodel_delete(sender,instance,**kwargs):#PassfalsesoFileFielddoesn'tsavethemodel.instance.file.delete(False)补充...
继续阅读 >