老师我这里修改地址,但是并不能保存。我说下我的理解:
`address_info = MemberAddress.query.filter_by( id = id,member_id = member_info.id ).first()
#如果存在说明数据库中关于这个用户的地址信息已经有了,那么直接用就好了。
if address_info:
model_address = address_info
else:
# 默认地址数量,就是说之前填写过多少个同一用户的不同地址,那现在就有多少种选择,或者选择设置新地址
default_address_count = MemberAddress.query.filter_by( is_default = 1,member_id = member_info.id ,status = 1).count()
model_address = MemberAddress()
model_address.member_id = member_info.id
model_address.is_default = 1 if default_address_count == 0 else 0
model_address.created_time = getCurrentDate()
model_address.nickname = nickname
model_address.mobile = mobile
model_address.address = address
model_address.province_id = province_id
model_address.province_str = province_str
model_address.city_id = city_id
model_address.city_str = city_str
model_address.area_id = district_id
model_address.area_str = district_str
model_address.updated_time = getCurrentDate()
db.session.add(model_address )
db.session.commit()
return jsonify(resp)`
这里的代码
(address_info = MemberAddress.query.filter_by( id = id,member_id = member_info.id ).first()
if address_info:
model_address = address_info)
显示,如果在数据库中能查到这个id的数据,就直接用,就不需要改,但是后面的编辑流程还是要走啊,还是要提交数据库啊。然后返回200成功码,然后继续跳出页面才对啊。为啥不能保存啊。