def gen_invite_code(request): ''' 生成用户的邀请码 返回是否成功 ''' u = request.user if u.pk == 1: # 针对管理员特出处理,每次生成5个邀请码 num = 5 else: num = u.invitecode_num - len(InviteCode.objects.filter(code_id=u.pk)) if num > 0: for i in range(num): code = InviteCode(type=0, code_id=u.pk) code.save() registerinfo = { 'title': '成功', 'subtitle': '添加邀请码{}个,请刷新页面'.format(num), 'status': 'success', } else: registerinfo = { 'title': '失败', 'subtitle': '已经不能生成更多的邀请码了', 'status': 'error', } result = json.dumps(registerinfo, ensure_ascii=False) return HttpResponse(result, content_type='application/json')
def gen_invite_code(request): ''' 生成用户的邀请码 返回是否成功 ''' u = request.user if u.pk == 1: # 针对管理员特出处理,每次生成5个邀请码 num = 5 else: num = u.invitecode_num - len(InviteCode.objects.filter(code_id=u.pk)) if num > 0: for i in range(num): code = InviteCode(type=0, code_id=u.pk) code.save() registerinfo = { 'title': '成功', 'subtitle': '添加邀请码{}个,请刷新页面'.format(num), 'status': 'success', } else: registerinfo = { 'title': '失败', 'subtitle': '已经不能生成更多的邀请码了', 'status': 'error', } result = json.dumps(registerinfo, ensure_ascii=False) return HttpResponse(result, content_type='application/json')
def gen_invite_code(request): ''' 生成用户的邀请码 返回是否成功 ''' u = request.user if u.pk == 1: # 针对管理员特出处理,每次生成5个邀请码 num = 5 else: num = u.invitecode_num - len(InviteCode.objects.filter(code_id=u.pk)) if num > 0: for i in range(num): code = InviteCode(type=0, code_id=u.pk) code.save() registerinfo = { 'title': '成功', 'subtitle': '添加邀请码{}个,请刷新页面'.format(num), 'status': 'success', } else: registerinfo = { 'title': '失败', 'subtitle': '已经不能生成更多的邀请码了', 'status': 'error', } return JsonResponse(registerinfo)