Fix: allow bulk edit with existing fields (#6625)

This commit is contained in:
shamoon 2024-05-07 14:26:07 -07:00 committed by GitHub
parent ce08400f4e
commit caec0ed4d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -140,16 +140,12 @@ def modify_custom_fields(doc_ids: list[int], add_custom_fields, remove_custom_fi
qs = Document.objects.filter(id__in=doc_ids).only("pk")
affected_docs = list(qs.values_list("pk", flat=True))
fields_to_add = []
for field in add_custom_fields:
for doc_id in affected_docs:
fields_to_add.append(
CustomFieldInstance(
document_id=doc_id,
field_id=field,
),
CustomFieldInstance.objects.update_or_create(
document_id=doc_id,
field_id=field,
)
CustomFieldInstance.objects.bulk_create(fields_to_add)
CustomFieldInstance.objects.filter(
document_id__in=affected_docs,
field_id__in=remove_custom_fields,