简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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