def goods_post(): name = request.args.get('name') category = request.args.get('category') num = request.args.get('num') last_time = request.args.get('last_time') stu_num = request.args.get('stu_num') s_academy = request.args.get('academy') if not (name and category and num and stu_num and s_academy and last_time): return error('提交参数不合法') academy = None if get_stu_academy(stu_num) and len(stu_num) == 8: academy = get_stu_academy(stu_num) else: return error('学号不符合规范') if academy != s_academy: return error('学号与学院不符合') userid = session['base_info']['userid'] user = User.query.filter_by(id=userid).first() good = Good(academy, name, category, num, last_time, user) good.save() return success('提交申请成功')
def addgood(request): goods = Good() goods.name = '运动鞋%d' % random.randrange(5) goods.brand = '耐克' goods.save() custom = Custom() custom.name = '张三%d' % random.randrange(5) custom.sex = '男' custom.save() #注意要在保存后添加 而且要用外键.add(主表对象) custom.good.add(goods) return HttpResponse('添加成功')