
如果要永久执行此 *** 作,则需要创建自己的FileStorage类
import osfrom django.conf import settingsfrom django.core.files.storage import FileSystemStorageclass MyFileStorage(FileSystemStorage): # This method is actually defined in Storage def get_available_name(self, name): if self.exists(name): os.remove(os.path.join(settings.MEDIA_ROOT, name)) return name # simply returns the name passed
现在在模型中,使用修改后的MyFileStorage
from mystuff.customs import MyFileStoragemfs = MyFileStorage()class SomeModel(model.Model): my_file = model.FileField(storage=mfs)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)