(self)
| 821 | |
| 822 | @transaction.atomic |
| 823 | def delete(self): |
| 824 | self.is_valid(raise_exception=True) |
| 825 | document_id = self.data.get("document_id") |
| 826 | source_file_ids = [ |
| 827 | doc["meta"].get("source_file_id") for doc in Document.objects.filter(id=document_id).values("meta") |
| 828 | ] |
| 829 | QuerySet(File).filter(id__in=source_file_ids).delete() |
| 830 | QuerySet(File).filter(source_id=document_id, source_type=FileSourceType.DOCUMENT).delete() |
| 831 | paragraph_ids = QuerySet(model=Paragraph).filter(document_id=document_id).values_list("id", flat=True) |
| 832 | # 删除问题 |
| 833 | delete_problems_and_mappings(paragraph_ids) |
| 834 | # 删除段落 |
| 835 | QuerySet(model=Paragraph).filter(document_id=document_id).delete() |
| 836 | # 删除向量库 |
| 837 | delete_embedding_by_document(document_id) |
| 838 | QuerySet(model=DocumentTag).filter(document_id=document_id).delete() |
| 839 | QuerySet(model=Document).filter(id=document_id).delete() |
| 840 | return True |
| 841 | |
| 842 | def refresh(self, state_list=None, with_valid=True): |
| 843 | if state_list is None: |
no test coverage detected