| 776 | ) |
| 777 | |
| 778 | def edit(self, instance: Dict, with_valid=False): |
| 779 | if with_valid: |
| 780 | self.is_valid(raise_exception=True) |
| 781 | _document = QuerySet(Document).get(id=self.data.get("document_id")) |
| 782 | if with_valid: |
| 783 | DocumentEditInstanceSerializer(data=instance).is_valid(document=_document) |
| 784 | update_keys = ["name", "is_active", "hit_handling_method", "directly_return_similarity", "meta"] |
| 785 | for update_key in update_keys: |
| 786 | if update_key in instance and instance.get(update_key) is not None: |
| 787 | _document.__setattr__(update_key, instance.get(update_key)) |
| 788 | _document.save() |
| 789 | return self.one() |
| 790 | |
| 791 | def cancel(self, instance, with_valid=True): |
| 792 | if with_valid: |