提交评论功能

This commit is contained in:
2024-05-06 12:35:09 +08:00
parent 645aafcadb
commit e48d34c52c
10 changed files with 215 additions and 8 deletions
+15
View File
@@ -117,3 +117,18 @@ class Task(AbstractModel):
def __str__(self):
return self.title
class Comment(models.Model): # 定义评论模型
# article = models.ForeignKey(to=Article, on_delete=models.DO_NOTHING, verbose_name='评论文章')
pinglun_id = models.IntegerField(verbose_name='评论id')
comment_content = models.TextField(verbose_name='评论内容')
user = models.ForeignKey(MindUser, on_delete=models.CASCADE) #评论人id
comment_time = models.DateTimeField(auto_now_add=True, verbose_name='评论时间')
pre_comment = models.ForeignKey('self', on_delete=models.DO_NOTHING, null=True,
verbose_name='父评论id') # 父级评论,如果没有父级则为空NULL, "self"表示外键关联自己
class Meta:
db_table = 'comment_tb'
verbose_name = '评论'
verbose_name_plural = verbose_name
+4 -1
View File
@@ -23,6 +23,7 @@ urlpatterns = [
path('reng_wu',to_rengwu), # 到任务界面
path('ke_cheng',to_kecheng), # 到课程界面
path('2_write',to_write), # 到协同边界页面
path('2_pinglun',to_pinglun), # 评论
path('2_star', to_star), # 到收藏界面
path('2_recycle', to_recycle), # 回收站
@@ -39,6 +40,7 @@ urlpatterns = [
path('star', JsMindStarView.as_view()), # 收藏思维导图
path('bianji', JsMindbianjiView.as_view()), # 跳转到协同编辑页面
path('pinglun', JsMindpinglunView.as_view()), # 跳转到评论页面
# ---------------------------------------------------
path('register', MindUserView.as_view()), # 用户注册
path('login', LoginView.as_view()), # 用户登录
@@ -52,6 +54,7 @@ urlpatterns = [
path('post_task/', post_task, name='post_task'),
path('post_kecheng/', post_kecheng, name='post_kecheng'),
path('come_kecheng/',come_kecheng, name='come_kecheng')
path('come_kecheng/',come_kecheng, name='come_kecheng'),
path('comment_control/',comment_control,name='comment_control') #提交评论处理的路由
]
+9 -1
View File
@@ -1,7 +1,7 @@
import json
from django.shortcuts import render
from server.models import Task,StudentandTercher
from server.models import Task,StudentandTercher,Comment
from server_auth.models import MindUser
@@ -21,6 +21,14 @@ def to_baiban(request):
"path": test_date}
return render(request, "html/baiban.html", param)
def to_pinglun(request):
test_date = request.GET.get('id')
comment_list = Comment.objects.filter(pinglun_id=test_date) # 从数据库找出该文章的评论数据对象
param = {"path": test_date,
"comment_list": comment_list}
print(test_date)
return render(request, "html/commont.html", param)
def to_share(request):
"""
分享页面
+26
View File
@@ -1,6 +1,7 @@
import uuid
from datetime import datetime as dt
from django.http import JsonResponse
from django_filters.rest_framework import *
from rest_framework.generics import *
from rest_framework.views import APIView
@@ -301,6 +302,31 @@ class JsMindbianjiView(LoginRequiredJSONMixin, ListAPIView):
return build_response(msg="操作成功", data=res)
class JsMindpinglunView(LoginRequiredJSONMixin, ListAPIView):
"""
思维导图分享view
"""
serializer_class = CooperationMindShareSerializer
filter_backends = [DjangoFilterBackend]
filter_class = CooperationMindShareFilter
pagination_class = DefaultNumberPagination
def post(self, request):
"""
点击协同编辑
"""
post_body = request.POST
id = post_body.get('id')
user = request.user
if id is None:
return build_response(code=CODE_FAILED, msg='参数错误')
if user.id is None:
return build_response(code=CODE_FAILED, msg='用户未登录')
print("----------------------------------------error")
res = f"http://127.0.0.1:8000/2_pinglun?test={id}"
return build_response(msg="操作成功", data=res)
class JsMindStarView(LoginRequiredJSONMixin, ListAPIView):
"""