06.获取对应课程评论接口

1.查询指定课程评论接口
 
1.1 course/urls.py 中还是查询课程的路由
 
router.register(r'course', views.CourseViewSet)
 
1.2 course/serializers.py 中添加评论相关查询
 
from goods.serializers import GoodsSerializer
class CourseDeepSerializer(CourseSerializer):
  comment = CommentSerializer(many=True)

class CommentSerializer(serializers.ModelSerializer):
  user = serializers.CharField(source='user.username')
  to_user = serializers.SerializerMethodField(required=False)

  class Meta:
    model = Comment
    fields = '__all__'

  def get_to_user(self,row):

    if row.to_user:

      return row.to_user.username

    return ''

 

2.测试获取评论接口
 
Http://192.168.56.100:8888/course/course/1/

 

3.前端代码
 
src\components\course_show.vue
 
src\components\common\comment.vue
posted @ 2020-11-07 19:36  深海海胆  阅读(111)  评论(0)    收藏  举报
Live2D