爲Camelot文檔說,它使用Elixir模型。由於SQLAlchemy已經包含了一段時間的declarative_base,我已經用它來代替Elixir用於其他應用程序。現在我想直接在Camelot中使用SQLAlchemy /聲明模型。Python Camelot與Elixir綁定了嗎?
有#2一個post,說柯萊特不綁藥劑和使用不同的模型將是可能的,但它並沒有說如何。
柯萊特的原始model.py
只有這樣的內容:
import camelot.types
from camelot.model import metadata, Entity, Field, ManyToOne, OneToMany, Unicode, Date, Integer, using_options
from camelot.view.elixir_admin import EntityAdmin
from camelot.view.forms import *
__metadata__ = metadata
我說我SQLAlchemy的模式,改變了model.py
這樣:
import camelot.types
from camelot.model import metadata, Entity, Field, ManyToOne, OneToMany, Unicode, Date, using_options
from camelot.view.elixir_admin import EntityAdmin
from camelot.view.forms import *
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
__metadata__ = metadata
Base = declarative_base()
class Test(Base):
__tablename__ = "test"
id = Column(Integer, primary_key=True)
text = Column(String)
它沒有工作。當我開始main.py
時,我可以在邊欄中看到GUI和Test
,但看不到任何行。這是回溯的尾巴:
File "/usr/lib/python2.6/dist-packages/camelot/view/elixir_admin.py", line 52, in get_query
return self.entity.query
AttributeError: type object 'Test' has no attribute 'query'
這是線46-52的elixir_admin.py
代碼:
@model_function
def get_query(self):
""":return: an sqlalchemy query for all the objects that should be
displayed in the table or the selection view. Overwrite this method to
change the default query, which selects all rows in the database.
"""
return self.entity.query
如果此代碼導致了問題,我怎麼重寫方法來改變默認查詢,使其工作?
你怎麼能使用SQLAlchemy /聲明性模型在Camelot?
是否使用的是柯萊特的版本
請你提供創造該問題的代碼?上面的代碼是 – Nilesh 2012-03-12 12:52:57
。我添加了原來的'model.py'代碼,以便您可以看到差異。 – boadescriptor 2012-03-12 13:00:20
是的,但我沒有找到任何聲明,你的代碼試圖訪問Test的'query'屬性。請發佈你的回溯。 – Nilesh 2012-03-12 13:06:32