xpke04

xpke04

V2EX 第 160255 号会员,加入于 2016-02-24 10:27:59 +08:00
xpke04
Python  •  xpke04
请教针对不同 Model 对象的相似处理的精简方法?
2018 年 4 月 8 日  •  最后回复来自 xpke04
4
问与答  •  xpke04
Nginx 反向代理到 https 出现 502
2017 年 12 月 6 日  •  最后回复来自 amrnxcdt
2
问与答  •  xpke04
docker 中多个容器访问 expose 端口的诡异问题
2017 年 10 月 27 日  •  最后回复来自 xpke04
1
酷工作  •  xpke04
网易游戏的 BI 岗位主要工作内容和能力要求
2016 年 2 月 23 日  •  最后回复来自 xpke04
1
xpke04 最近回复了
回复了 xpke04 创建的主题 › 请教针对不同 Model 对象的相似处理的精简方法?2018 年 4 月 9 日
v2ex 贴代码太不方便了,我把问题移至 segmentfault 了, https://segmentfault.com/q/1010000014261968
回复了 xpke04 创建的主题 › 请教针对不同 Model 对象的相似处理的精简方法?2018 年 4 月 9 日
补充一下描述,

``` python
def change_docorder():
reqdata = request.json
op = reqdata["op"]
docid = reqdata["docid"]

# 如果是上移文档顺序
if op == "up":
another = DocItem.query.filter(and_(DocItem.category_id == docitem.category_id,
DocItem.order < docitem.order)).order_by(DocItem.order.desc()).first()
if another is None:
return error_response(u"无法继续移动该文档顺序!")
tmp = another.order
another.order = docitem.order
docitem.order = tmp
another.save()
docitem.save()
elif op == "down":
another = DocItem.query.filter(and_(DocItem.category_id == docitem.category_id,
DocItem.order>docitem.order)).order_by(DocItem.order.asc()).first()
if another is None:
return error_response(u"无法继续移动该文档顺序!")
tmp = another.order
another.order = docitem.order
docitem.order = tmp
another.save()
docitem.save()
else:
return make_response(u"非法的操作!")
return make_response(json.dumps({
"status": "success",
"msg": u"修改文档顺序成功!"
}))
```

这是针对 DocItem 这个 model 进行的调整顺序操作,还有其他的几个 model 对象需要进行相同的操作,如何如果都分别写一个函数来实现功能,最终代码只有类名 `DocItem` 是不一样的。

以上是对问题的补充描述。
回复了 xpke04 创建的主题 › docker 中多个容器访问 expose 端口的诡异问题2017 年 10 月 27 日
补充,docker 网络使用的是默认的 bridge 模式,另外,在容器中是能够访问主机上绑定的其他端口的服务的,但是不能访问容器 expose 出来的端口上的服务。
回复了 xpke04 创建的主题 › 网易游戏的 BI 岗位主要工作内容和能力要求2016 年 2 月 24 日
给自己挽尊。
© 2026 V2EX · 16ms · 3.9.8.5