mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 09:54:54 +00:00
refactor: adjust paragraph position handling to insert new paragraphs at the top
--bug=1057642 --user=刘瑞斌 【知识库】文档中添加分段,最后添加的没显示在最上面 https://www.tapd.cn/62980211/s/1719802
This commit is contained in:
parent
276378a9ae
commit
cd25bcf074
|
|
@ -258,18 +258,15 @@ class ParagraphSerializers(serializers.Serializer):
|
|||
problem_model_list, problem_paragraph_mapping_list = (
|
||||
ProblemParagraphManage(problem_paragraph_object_list, knowledge_id)
|
||||
.to_problem_model_list())
|
||||
# 插入段落
|
||||
max_position = Paragraph.objects.filter(document_id=document_id).aggregate(
|
||||
max_position=Max('position')
|
||||
)['max_position'] or 0
|
||||
paragraph.position = max_position + 1
|
||||
# 新加的在最上面
|
||||
paragraph.position = 0
|
||||
paragraph.save()
|
||||
# 调整位置
|
||||
if 'position' in instance:
|
||||
if type(instance['position']) is not int:
|
||||
instance['position'] = max_position + 1
|
||||
instance['position'] = 0
|
||||
else:
|
||||
instance['position'] = max_position + 1
|
||||
instance['position'] = 0
|
||||
|
||||
ParagraphSerializers.AdjustPosition(data={
|
||||
'paragraph_id': str(paragraph.id),
|
||||
|
|
|
|||
Loading…
Reference in New Issue