我想删除与文件字段关联的文件但它不起作用。
请问可以修吗?
模型.py
class Picture(models.Model):
file = models.FileField(upload_to="pictures")
slug = models.SlugField(max_length=50, blank=True)
def __unicode__(self):
return self.file
def getFileName(self):
return self.docfile.name
视图.py
def delete(self, request, *args, **kwargs):
"""
This does not actually delete the file, only the database record.
"""
self.object = self.get_object()
path = "/media/pictures" + '/' + self.object.name
#path = MEDIA_ROOT + '/' + self.object.name
#path = MEDIA_ROOT + '/' + self.object.getFileName()
self.object.delete()
os.remove(path)