code: def delete_attachment(self, attachment):
          
  
          # Get the holding parent of this attachment
          parent = None
          if attachment.getLinkedRequests():
              # Holding parent is an AR
              parent = attachment.getRequest()
          elif attachment.getLinkedAnalyses():
              # Holding parent is an Analysis
              parent = attachment.getAnalysis()
  
          if parent is None:
              logger.warn(
                  "Attachment {} is nowhere assigned. This should never happen!"
                  .format(repr(attachment)))
              return False
  
          # Get the other attachments of the holding parent
          attachments = parent.getAttachment()
  
          # New attachments to set
          if attachment in attachments:
              attachments.remove(attachment)
  
          # Set the attachments w/o the current attachments
          parent.setAttachment(attachments)
  
          retain = False
  
          # Attachment is referenced by another Analysis
          if attachment.getLinkedAnalyses():
              holder = attachment.getAnalysis()
              logger.info("Attachment {} referenced by {} -> RETAIN"
                          .format(repr(attachment), repr(holder)))
              retain = True
  
          # Attachment is referenced by another AR
          if attachment.getLinkedRequests():
              holder = attachment.getRequest()
              logger.info("Attachment {} referenced by {} -> RETAIN"
                          .format(repr(attachment), repr(holder)))
              retain = True
  
          # Delete attachment finally
          if retain is False:
              client = api.get_parent(attachment)
              client.manage_delObjects([attachment.getId(), ])
docs: Delete attachment from the AR or Analysis
  
          The attachment will be only deleted if it is not further referenced by
          another AR/Analysis.