code: def owned_pre_save(sender, document, **kwargs):
      '''
      Owned mongoengine.pre_save signal handler
      Need to fetch original owner before the new one erase it.
      '''
      if not isinstance(document, Owned):
          return
      changed_fields = getattr(document, '_changed_fields', [])
      if 'organization' in changed_fields:
          if document.owner:
              # Change from owner to organization
              document._previous_owner = document.owner
              document.owner = None
          else:
              # Change from org to another
              # Need to fetch previous value in base
              original = sender.objects.only('organization').get(pk=document.pk)
              document._previous_owner = original.organization
      elif 'owner' in changed_fields:
          if document.organization:
              # Change from organization to owner
              document._previous_owner = document.organization
              document.organization = None
          else:
              # Change from owner to another
              # Need to fetch previous value in base
              original = sender.objects.only('owner').get(pk=document.pk)
              document._previous_owner = original.ownef owned_pre_save(sender, document, **kwargs):
      '''
      Owned mongoengine.pre_save signal handler
      Need to fetch original owner before the new one erase it.
      '''
      if not isinstance(document, Owned):
          return
      changed_fields = getattr(document, '_changed_fields', [])
      if 'organization' in changed_fields:
          if document.owner:
              # Change from owner to organization
              document._previous_owner = document.owner
              document.owner = None
          else:
              # Change from org to another
              # Need to fetch previous value in base
              original = sender.objects.only('organization').get(pk=document.pk)
              document._previous_owner = original.organization
      elif 'owner' in changed_fields:
          if document.organization:
              # Change from organization to owner
              document._previous_owner = document.organization
              document.organization = None
          else:
              # Change from owner to another
              # Need to fetch previous value in base
              original = sender.objects.only('owner').get(pk=document.pk)
              document._previous_owner = original.owner
docs: Owned mongoengine.pre_save signal handler
      Need to fetch original owner before the new one erase it.