我一直在试图弄清楚如何迭代SQLAlchemy模型中定义的列列表.我希望它能为一些模型编写一些序列化和复制方法.我不能只迭代obj.__dict__它,因为它包含很多特定于SA的项目.
任何人都知道如何从以下获取id和desc名称?
class JobStatus(Base):
__tablename__ = 'jobstatus'
id = Column(Integer, primary_key=True)
desc = Column(Unicode(20))
Run Code Online (Sandbox Code Playgroud)
在这个小案例中,我可以轻松创建:
def logme(self):
return {'id': self.id, 'desc': self.desc}
Run Code Online (Sandbox Code Playgroud)
但我更喜欢自动生成的东西dict(对于较大的对象).
谢谢你的帮助.
我有一个Pylons应用程序,我正在使用SqlAlchemy声明模型.为了使代码更清晰,我将一个.query添加到SA Base并继承我的所有模型.
所以在我的app.model.meta中我有
Base = declarative_base()
metadata = Base.metadata
Session = scoped_session(sessionmaker())
Base.query = Session.query_property(Query)
Run Code Online (Sandbox Code Playgroud)
我认为将其继承到app.model.mymodel并将其声明为meta.Base的子代.这让我可以把我的查询写成
mymodel.query.filter(mymodel.id == 3).all()
Run Code Online (Sandbox Code Playgroud)
问题是pylint没有看到.query作为我模型的有效属性.
E:102:JobCounter.reset_count: Class 'JobCounter' has no 'query' member
Run Code Online (Sandbox Code Playgroud)
显然,这个错误遍布整个地方,因为它发生在任何进行任何查询的模型上.我不想只是跳过错误,因为它可能会指出非orm类的一些事情,但我必须错过pylint接受这个的东西.
任何提示?
我正在运行的OSS应用程序上使用FontAwesome字体,我似乎无法通过Firefox的字体清理器.
这些文件都在同一个域中提供,路径是正确的,我正在使用FontAwesome的官方CSS,当通过他们的网站和本地文档提供服务时,它可以在Firefox中运行.
所以我一定要错过一些简单的东西.
实时网址:https://bmark.us
[11:39:02.945] downloadable font: invalid version tag (font-family: "FontAwesome" style:normal weight:normal stretch:normal src index:0)
source: http://127.0.0.1:6543/static/font/fontawesome-webfont.eot @ http://127.0.0.1:6543/static/css/responsive.css
[11:39:02.945] downloadable font: rejected by sanitizer (font-family: "FontAwesome" style:normal weight:normal stretch:normal src index:0)
source: http://127.0.0.1:6543/static/font/fontawesome-webfont.eot @ http://127.0.0.1:6543/static/css/responsive.css
Run Code Online (Sandbox Code Playgroud)
当我尝试通过dev更正此错误时,是Firefox的错误示例.我试图做完全根路径/静态/字体和相对于CSS ../font/,它总是失败,我的这些错误.
一切都适用于Chrome等.似乎Firefox只恨我.我搜索了其他答案,我得到了整个系列的字体.
https://github.com/mitechie/Bookie/tree/develop/bookie/static/font
谢谢你的任何提示.
我正在尝试使用bmarks_tags的辅助表执行一个跨越bmarks和标记之间的多个关系的查询.该查询涉及多个子查询,我需要DISTINCT一列.我后来想通过DISTINCT'd ID将它加入到另一个表中.
我尝试了几种方法,这似乎最接近:
tagid = alias(Tag.tid.distinct())
test = select([bmarks_tags.c.bmark_id],
from_obj=[bmarks_tags.join(DBSession.query(tagid.label('tagid'))),
bmarks_tags.c.tag_id == tagid])
return DBSession.execute(qry)
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
? AttributeError: '_UnaryExpression' object has no attribute 'named_with_column'
Run Code Online (Sandbox Code Playgroud)
有谁知道我如何跨bmarks_tags.tag_id和Tag.tid.distinct()的结果执行连接?
谢谢
架构:
# this is the secondary table that ties bmarks to tags
bmarks_tags = Table('bmark_tags', Base.metadata,
Column('bmark_id', Integer, ForeignKey('bmarks.bid'), primary_key=True),
Column('tag_id', Integer, ForeignKey('tags.tid'), primary_key=True)
)
class Tag(Base):
"""Bookmarks can have many many tags"""
__tablename__ = "tags"
tid = Column(Integer, autoincrement=True, primary_key=True)
name = Column(Unicode(255), unique=True)
Run Code Online (Sandbox Code Playgroud) 使用新发布的csslint,我想尝试将其挂钩到vim作为.css文件的makefile.我很难让多行错误格式适用于输出.
到目前为止,我最好的结果是:
au BufRead *.css set makeprg=csslint\ %
au BufRead *.css set errorformat=%A%f:,%C%n:\ warning\ at\ line\ %l\,\ col\ %c,%C%m,%C%.%#,%C%.%#
Run Code Online (Sandbox Code Playgroud)
但这并没有得到正确的行/列数.我在我的quickfix窗口中收到此输出:
|| csslint: There are 33 errors and warnings in bookie.css.
||
bookie.css|| 1: warning Too many font-size declarations (13), abstraction needed.
bookie.css|| 2: warning at line 3, col 3 Rule is empty. BODY {
bookie.css|| 3: warning at line 12, col 12 Values of 0 shouldn't have units specified. padding: .5em 0em;
bookie.css|| 4: warning at line 13, col 13 …Run Code Online (Sandbox Code Playgroud)