From 61518a66e417c2c210291d0b589dae8e02a8083f Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 8 Feb 2022 15:04:13 +0100 Subject: Document duplicate - do not duplicate image - allow redirection to modify --- ishtar_common/utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index e6283ae5e..e27b26e70 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -2029,6 +2029,7 @@ PRIVATE_FIELDS = ("id", "history_modifier", "order", "uuid") def duplicate_item(item, user=None, data=None): model = item.__class__ new = model.objects.get(pk=item.pk) + data = data or {} for field in model._meta.fields: # pk is in PRIVATE_FIELDS so: new.pk = None and a new @@ -2039,9 +2040,11 @@ def duplicate_item(item, user=None, data=None): setattr(new, field.name, None) if user: new.history_user = user - if data: - for k in data: - setattr(new, k, data[k]) + for k in data: + setattr(new, k, data[k]) + exclude_fields = getattr(model, "DUPLICATE_EXCLUDE", []) + for k in exclude_fields: + setattr(new, k, None) new.save() if hasattr(user, "user_ptr"): if hasattr(new, "history_creator"): -- cgit v1.2.3