如何从 Django 管理表单提交访问 request.FILES?
How to access request.FILES from django admin form submission?
@receiver(pre_save, sender=Document, dispatch_uid='question_save_signal')
def log_save_question(sender, instance, using, **kwargs):
p = instance
这是我在 django admin 中用来拦截保存的代码。在此函数内部,我需要访问 request.FILES 以访问刚刚在 ImageField 中选择并正在提交的新文件。
你会怎么做?
当你有一个pre_save函数时,属性已经设置到对象,但是它还没有保存到数据库中。
因此,如果您的文档模型具有属性 image
,您应该能够通过以下方式访问它:instance.image
@receiver(pre_save, sender=Document, dispatch_uid='question_save_signal')
def log_save_question(sender, instance, using, **kwargs):
p = instance
这是我在 django admin 中用来拦截保存的代码。在此函数内部,我需要访问 request.FILES 以访问刚刚在 ImageField 中选择并正在提交的新文件。 你会怎么做?
当你有一个pre_save函数时,属性已经设置到对象,但是它还没有保存到数据库中。
因此,如果您的文档模型具有属性 image
,您应该能够通过以下方式访问它:instance.image