东方耀AI技术分享

标题: 40、python_django_web开发_完成课程机构的收藏功能Ajax提交_笔记 [打印本页]

作者: 东方耀    时间: 2017-11-26 23:02
标题: 40、python_django_web开发_完成课程机构的收藏功能Ajax提交_笔记


40、python_django_web开发_完成课程机构的收藏功能Ajax提交_笔记


收藏功能 Ajax提交
  1. def post(self, request):
  2.     fav_type = request.POST.get('fav_type', '0')
  3.     fav_id = request.POST.get('fav_id', '0')
  4.     # 判断用户是否登录
  5.     if not request.user.is_authenticated():
  6.         return HttpResponse('{"status":"fail", "msg":"用户未登录"}', content_type='application/json')
  7.     # 查询收藏记录是否存在 如果存在则取消收藏 如果不存在则去收藏
  8.     exist_records = UserFavorite.objects.filter(user=request.user, fav_id=int(fav_id), fav_type=int(fav_type))
  9.     if exist_records:
  10.         exist_records.delete()
  11.         return HttpResponse('{"status":"success", "msg":"收藏"}', content_type='application/json')
  12.     else:
  13.         user_fav = UserFavorite()
  14.         if int(fav_id) > 0 and int(fav_type) > 0:
  15.             user_fav.user = request.user
  16.             user_fav.fav_id = int(fav_id)
  17.             user_fav.fav_type = int(fav_type)
  18.             user_fav.save()
  19.             return HttpResponse('{"status":"success", "msg":"已收藏"}', content_type='application/json')
  20.         else:
  21.             return HttpResponse('{"status":"fail", "msg":"收藏出错"}', content_type='application/json')


  22. has_fav = False
  23. if request.user.is_authenticated():
  24.     if UserFavorite.objects.filter(user=request.user, fav_id=course_org.id, fav_type=3):
  25.         has_fav = True
复制代码



作者: peter    时间: 2017-12-6 09:26
有些视频有权限有些没有呢?
作者: 东方耀    时间: 2017-12-6 10:15
peter 发表于 2017-12-6 09:26
有些视频有权限有些没有呢?

有权限 需要vip才行 40集以后的 联系qq 309623978
作者: xiaoma    时间: 2017-12-14 14:52
1
作者: zhongxuan    时间: 2018-2-28 20:15
xmxw


xmxw
作者: 渡口    时间: 2018-6-8 22:19
非常感谢
作者: Libing    时间: 2018-10-29 16:09
6666666666666666666666666666666666666666666666666
作者: Libing    时间: 2018-10-29 16:09
6666666666666666666666666666666
作者: pythond_djongo    时间: 2018-12-15 14:10
6666666666666666666666666666
作者: pythond_djongo    时间: 2018-12-15 14:22

谢谢楼主分享
作者: xiaodan    时间: 2018-12-26 15:46
谢谢老师
作者: tchsong    时间: 2019-11-8 12:38
python_django_web开发_完成课程机构的收藏功能Ajax提交_笔记




欢迎光临 东方耀AI技术分享 (http://www.ai111.vip/) Powered by Discuz! X3.4