From a8bafe58cc961e2a5d37799190b718ca39441753 Mon Sep 17 00:00:00 2001 From: Elias Hernandis Date: Sun, 22 Dec 2024 18:38:28 +0100 Subject: [PATCH] skip updating existing attachments --- anchor/models/fields/single_attachment.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/anchor/models/fields/single_attachment.py b/anchor/models/fields/single_attachment.py index fcf2e78..3b8a06e 100644 --- a/anchor/models/fields/single_attachment.py +++ b/anchor/models/fields/single_attachment.py @@ -31,11 +31,13 @@ def __get__(self, *args, **kwargs) -> Attachment | None: def __set__(self, instance, value): if isinstance(value, Attachment): - value.object_id = instance.id - value.content_type = ContentType.objects.get_for_model(instance) - value.name = self.name - value.order = 0 - value.save() + if value._state.adding: + value.object_id = instance.id + value.content_type = ContentType.objects.get_for_model(instance) + value.name = self.name + value.order = 0 + value.save() + return if isinstance(value, Blob):