相关疑难解决方法(0)

django 文件上传 - 编辑模板更新时图像被删除

我使用 django 允许用户上传图像以及描述图像标题的文本。

用户应该能够使用编辑模板编辑图像标题并更改图像文件。这在某种程度上确实有效。

我可以在编辑模板中显示图像文件和图像标题进行编辑。我遇到的问题是,当我在文件上传输入中不包含图像文件时(用户只想更改图像标题而不是图像文件),我的代码确实更改了图像标题,但图像文件被删除从数据库中删除(物理映像文件不会从文件系统中删除)。

我可以成功更新图像详细信息,但用户必须在文件上传输入字段中包含新的图像文件或相同的图像文件,图像标题和图像详细信息才能成功更新。

看来用户必须在文件上传输入字段中包含图像文件。我试图让我的代码像 django admin 一样工作,用户不必每次更改图像标题时都包含图像文件。

如何允许用户更新图像详细信息,而无需每次用户想要更改图像标题时重新上传图像文件?

这是我的 models.py 代码:

编辑#2 - 添加 FillableModelWithLanguageVersion 和 LanguageVersion

# START: ATTACHMENT DETAILS MODEL.
def _get_document_upload_location(instance, filename):
    """
    Using a function instead of a lambda to make migrations happy. DO NOT remove or rename this function in the future, as it will break migrations.
    @param instance: model instance that owns the FileField we're generating the upload filename for.
    @param filename: Original file name assigned by django.
    """ …
Run Code Online (Sandbox Code Playgroud)

python django file-upload image django-file-upload

0
推荐指数
1
解决办法
2478
查看次数

标签 统计

django ×1

django-file-upload ×1

file-upload ×1

image ×1

python ×1