diff --git a/swimlane/core/fields/attachment.py b/swimlane/core/fields/attachment.py index 1f956488..9aeb5e76 100644 --- a/swimlane/core/fields/attachment.py +++ b/swimlane/core/fields/attachment.py @@ -5,7 +5,7 @@ class AttachmentCursor(FieldCursor): - """Allows creation and iteration of attachments""" + """Allows creation, deletion, and iteration of attachments""" def add(self, filename, stream, content_type=None): """Upload a new attachment, and add it to current fields raw data to be persisted on save @@ -34,6 +34,24 @@ def add(self, filename, stream, content_type=None): return attachment + def delete(self, attachment): + """Deletes an attachment and removes it from the current field to be persisted on save + + Args: + attachment (swimlane.core.resources.attachment.Attachment): Abstraction of an attachment from an AttachmentsField + """ + + file_id = attachment.file_id + response = self._record._swimlane.request( + 'DELETE', + 'attachment/{}'.format(file_id) + ) + + self._elements.remove(attachment) + + self._sync_field() + + class AttachmentsField(MultiSelectField):