东方耀AI技术分享
标题:
40、python_django_web开发_完成课程机构的收藏功能Ajax提交_笔记
[打印本页]
作者:
东方耀
时间:
2017-11-26 23:02
标题:
40、python_django_web开发_完成课程机构的收藏功能Ajax提交_笔记
40、python_django_web开发_完成课程机构的收藏功能Ajax提交_笔记
收藏功能
Ajax提交
def post(self, request):
fav_type = request.POST.get('fav_type', '0')
fav_id = request.POST.get('fav_id', '0')
# 判断用户是否登录
if not request.user.is_authenticated():
return HttpResponse('{"status":"fail", "msg":"用户未登录"}', content_type='application/json')
# 查询收藏记录是否存在 如果存在则取消收藏 如果不存在则去收藏
exist_records = UserFavorite.objects.filter(user=request.user, fav_id=int(fav_id), fav_type=int(fav_type))
if exist_records:
exist_records.delete()
return HttpResponse('{"status":"success", "msg":"收藏"}', content_type='application/json')
else:
user_fav = UserFavorite()
if int(fav_id) > 0 and int(fav_type) > 0:
user_fav.user = request.user
user_fav.fav_id = int(fav_id)
user_fav.fav_type = int(fav_type)
user_fav.save()
return HttpResponse('{"status":"success", "msg":"已收藏"}', content_type='application/json')
else:
return HttpResponse('{"status":"fail", "msg":"收藏出错"}', content_type='application/json')
has_fav = False
if request.user.is_authenticated():
if UserFavorite.objects.filter(user=request.user, fav_id=course_org.id, fav_type=3):
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