From 0285ed25b17a61dc2f747c99faaa03b2ef19b9ff Mon Sep 17 00:00:00 2001 From: maoshen Date: Tue, 14 Apr 2026 12:22:13 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=89=8D=E7=AB=AF=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E6=89=B9=E6=B3=A8=EF=BC=88GenericForeignKey?= =?UTF-8?q?=20=E6=97=A0=E6=B3=95=E7=94=A8=20related=5Fname=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/diary/serializers.py | 2 +- frontend/index.html | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/backend/diary/serializers.py b/backend/diary/serializers.py index e161c95..d822c25 100755 --- a/backend/diary/serializers.py +++ b/backend/diary/serializers.py @@ -43,7 +43,7 @@ class DiaryEntrySerializer(serializers.ModelSerializer): class Meta: model = DiaryEntry - fields = '__all__' + fields = ['id', 'progresses', 'linked_tasks', 'experiences', 'comments', 'date', 'title', 'content', 'completed_tasks', 'learned', 'problems', 'reflections', 'improvements', 'plans', 'created_at', 'updated_at'] class TaskSerializer(serializers.ModelSerializer): status_display = serializers.CharField(source='get_status_display', read_only=True) diff --git a/frontend/index.html b/frontend/index.html index ae48888..6fa0c05 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -281,6 +281,15 @@ scores: { quality: '', efficiency: '', creativity: '', learning: '' } }; + async function loadComments(contentType, objectId) { + try { + const res = await fetch(`${API_BASE}/comments/by_content/?content_type=${contentType}&object_id=${objectId}`); + return await res.json(); + } catch (e) { + return []; + } + } + async function loadData() { try { const [taskStatsRes, tasksRes, diaryStatsRes, entriesRes, expStatsRes, experiencesRes] = await Promise.all([ @@ -297,6 +306,18 @@ state.allEntries = await entriesRes.json(); state.expStats = await expStatsRes.json(); state.allExperiences = await experiencesRes.json(); + + // 加载所有批注 + for (const entry of state.allEntries) { + entry.comments = await loadComments('diary', entry.id); + } + for (const task of state.allTasks) { + task.comments = await loadComments('task', task.id); + } + for (const exp of state.allExperiences) { + exp.comments = await loadComments('experience', exp.id); + } + render(); } catch (error) { document.getElementById('app').innerHTML = `
加载失败:${error.message}
`;