2016-10-04 70 views

回答

3

有这样的文档的example

from sqlalchemy.util import OrderedDict 
from sqlalchemy.orm.collections import MappedCollection 

class NodeMap(OrderedDict, MappedCollection): 
    """Holds 'Node' objects, keyed by the 'name' attribute with insert order maintained.""" 

    def __init__(self, *args, **kw): 
     MappedCollection.__init__(self, keyfunc=lambda node: node.name) 
     OrderedDict.__init__(self, *args, **kw) 

使用方法很简单:

foo = relationship(..., collection_class=NodeMap) 
+0

在这里,我想通过我的所有文档的阅读,一定是错过了这个...谢谢男人,并为麻烦抱歉 –