简体   繁体   English

Django pre_save未触发

[英]Django pre_save is not triggered

I'm creating an instance of a model (Container), and it seems like the pre_save function is not triggered. 我正在创建一个模型实例(容器),并且似乎未触发pre_save函数。

This is the class in the 'signals': 这是“信号”中的类:

class ContainerCreatedMixin(object):
  @staticmethod
  @receiver(pre_save, sender=Container)
  def container_pre_save(sender, instance, **kwargs):
      # create container folder if not created yet
      if instance.folder_created_at is None:
          is_folder_created = ContainerCreatedMixin().create_folder(instance)

          if is_folder_created:
              instance.folder_created_at = now()

  def create_virtual_folder(self, container):
     try:
        ...... 

Using the receiver decorator on a class method doesn't really make sense. 在类方法上使用接收器装饰器实际上没有任何意义。

Put your decorated method out of class and it should be registered if the file is imported. 将修饰的方法放在类之外,如果文件已导入,则应将其注册。 Also, there is no need of creating Mixings for the following. 同样,无需为以下内容创建混合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM