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

浙公网安备 33010602011771号