PyCharm SQLAlchemy 自动完成 [英] PyCharm SQLAlchemy autocomplete

查看:93
本文介绍了PyCharm SQLAlchemy 自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始评估 PyCharm 3 专业版,因为我将参与多个 Pyramid + SQLAlchemy 项目.我非常希望拥有的一件事是 SQLAlchemy 自动完成功能.

I started evaluating PyCharm 3 professional edition because I will be working on several Pyramid + SQLAlchemy projects. One of the things I would really love to have is SQLAlchemy autocomplete.

我在之后使用炼金术支架创建了一个新的入门项目这些说明.我还为我在这个项目中使用的解释器和虚拟环境安装了 SQLAlchemy 包.

I created a new starter project with the alchemy scaffold following these instructions. I also installed the SQLAlchemy package for the interpreter and virtual environment I am using for this project.

另外,当我为这段代码新建一个pycharm项目时,IDE建议我安装pyramid、sqlalchemy等包.我当然接受了这个建议,让 IDE 安装所有这些包.

Also, when I created a new pycharm project for this code, the IDE suggested me to install the pyramid, sqlalchemy and other packages. Of course I accepted the suggestion and let the IDE install all of those packages.

models.py文件中,DBSession声明如下:

In the models.py file, the DBSession is declared as follows:

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))

在views.py文件中,DBSession是这样使用的:

In the views.py file, the DBSession is used this way:

one = DBSession.query(MyModel).filter(MyModel.name == 'one').first()

所以我开始使用 IDE 并做了这样的事情:输入 DBSession.IDE 只是给了我一些建议,其中没有列出查询"功能.然后我尝试输入:DBSession.query(MyModel).并按 Ctrl+Space 尝试获取建议并显示无建议"消息.

So I started playing with the IDE and did something like this: typed DBSession. and the IDE just gave me some few suggestions, within which the 'query' function was not listed. Then I tried typing: DBSession.query(MyModel). and pressed Ctrl+Space to try to get suggestions and a 'No suggestions' message showed up.

我真的很想得到 SQLAlchemy 对我可以在我的 DBSession 变量上使用的函数的建议(例如 filterfilter_byfirst, 等等).我会说这对我来说是强制性的:)

I would really like to have the SQLAlchemy suggestions of functions that I could use on my DBSession variable (like filter, filter_by, first, etc). I would say that this is mandatory for me :)

有什么我遗漏的吗?或者,PyCharm 不支持这个?

Is there something I am missing? Or, PyCharm doesn't support this?

推荐答案

我找到的解决方案(从网上某处找到的)是像这样输入提示 DBSession 实例:

The solution I've found to this (picked up from somewhere on the web) was to type hint the DBSession instance like this:

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
""":type: sqlalchemy.orm.Session"""

在此之后,代码完成似乎在项目中的任何地方都可以正常工作

After this the code completion seems to work fine everywhere in the project

这篇关于PyCharm SQLAlchemy 自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆