2014-09-28 3 views
2

사용자, ShoppingItem 또는 ShoppingList 항목 (아래 코드)을 편집하려고하면 turbogears 관리자 컨트롤러에 오류가 발생합니다. 오류는 AttributeError: 'function' object has no attribute 'primary_key'입니다. 프레임의 지역 변수는 항상 동일하게 돌아올 :Turbogears2 다 대다 관계로 오류가 발생했습니다.

mapper 
<Mapper at 0x3719810; ShoppingList> 
fields 
['id'] 
self  
<sprox.sa.provider.SAORMProvider instance at 0x03E537B0> 
value 
<bound method OrderedProperties.items of <sqlalchemy.util._collections.OrderedProperties object at 0x037199F0>> 
entity 
<class 'insertmealhere.model.shoppinglist.ShoppingList'> 
field_name 
'items' 

나는이하고 코드의 다른 구성하지하는 다른 대다 관계 사이의 차이가 무엇인지 알아내는 데 문제가 이 오류가 발생했습니다. 현재 Windows 8.1 시스템에서 Python 2.7.8에서 Turbogears 2.2를 실행 중입니다. 어떤 도움이라도 대단히 감사합니다.

list_item_table = Table("list_item_table", metadata, 
        Column('item_id', Integer, ForeignKey('shopping_item.id', onupdate="CASCADE", ondelete="CASCADE"), primary_key=True), 
        Column('list_id', Integer, ForeignKey('shopping_list.id', onupdate="CASCADE", ondelete='CASCADE'), primary_key=True)) 


class ShoppingItem(DeclarativeBase): 
__tablename__ = "shopping_item" 

id = Column(Integer, primary_key=True) 
name = Column(String(50)) 
quantity = Column(String(5)) 
measure = Column(String(10)) 

# less important optional parameters that will be useful for users 
brand = Column(String(50)) 

list_id = Column(Integer, ForeignKey('shopping_list.id')) 
shopping_list = relation("ShoppingList", secondary=list_item_table, backref="items") 

def get_owner_id(self): 
    return self.list.user_id 

@classmethod 
def delete_list(cls, id, user_id): 
    item = DBSession.query(cls).filter_by(id=id).one() # get the item from the given ID 
    if item.get_owner_id() == user_id: # owned by current user 
     DBSession.delete(item) # delete from shopping list 
     return True 
    flash(_("You do not have authorization to perform that action.")) 
    return False 



class ShoppingList(DeclarativeBase): 
__tablename__ = 'shopping_list' 

id = Column(Integer, primary_key=True) 
date = Column(Date, index=True, nullable=False) 
static = Column(Boolean, nullable=False, default=False) 
# static is true if the items from the meal plan have been imported into the shopping list. Once done you can edit 
# the items in the shopping list, remove items, etc. Until the shopping list is made static it is impossible to edit 
# the items that are imported from the schedule as they do not exist in the shopping list! (and we do not want to 
# edit them in the recipe! 

user_id = Column(Integer, ForeignKey('tg_user.user_id')) 
user = relation("User", backref="shopping_lists") 

date_user_list = Index('date_user_list', 'date', 'user_id') 

답변

0

은 아마 SQLAlchemy의 혼란 년대 ShoppingItem 모델 클래스의 list_id = Column(Integer, ForeignKey('shopping_list.id'))있어?