class Image(models.Model):
name = models.CharField(max_length=255, null=False, verbose_name="图片名称")
class Meta:
db_table = 'Image'
verbose_name = '图片'
verbose_name_plural = verbose_name
def delete(self, *args, **kwargs):
//图片名即文件名(包含文件后缀)
os.remove(settings.IMAGES_DIR + self.name)
super().delete(*args, **kwargs)
----------------------------------------------------------------
MEDIA_URL = os.path.join(BASE_DIR, 'resources/')
MEDIA_ROOT = os.path.join(BASE_DIR, 'resources')
IMAGES_DIR = os.path.join(MEDIA_ROOT, 'images/')
------------------------------------------------------------
图片存储在:项目根目录/resources/images/
使用了X-Admin
删除记录时,没有把文件也删除了