2009-12-22 2 views
0

두 테이블 (intakemodule) 간의 연결 관계를 만들려고했습니다. 각 섭취량은 모듈과 일대 다 관계를 유지합니다. 그러나 각 과목에 할당 된 교과 과정이 있으며 각 과목에는 각 섭취량에 고유 한 duedate이 있습니다. 선언적 기본을 사용하여 연결 관계를 지정하는 방법

나는이 시도했지만 작동 일부러 : 내가 할 때

intake_modules_table = Table('tg_intakemodules',metadata, 
    Column('intake_id',Integer,ForeignKey('tg_intake.intake_id', 
       onupdate="CASCADE",ondelete="CASCADE")), 
    Column('module_id',Integer,ForeignKey('tg_module.module_id', 
       onupdate ="CASCADE",ondelete="CASCADE")), 
    Column('dueddate', Unicode(16)) 
) 

class Intake(DeclarativeBase): 

    __tablename__ = 'tg_intake' 

    #{ Columns 
    intake_id = Column(Integer, autoincrement=True, primary_key=True) 
    code = Column(Unicode(16)) 
    commencement = Column(DateTime) 
    completion = Column(DateTime) 

    #{ Special methods 
    def __repr__(self): 
     return '"%s"' %self.code 
    def __unicode__(self): 
     return self.code 
    #} 


class Module(DeclarativeBase): 

    __tablename__ ='tg_module' 

    #{ Columns 
    module_id = Column(Integer, autoincrement=True, primary_key=True) 
    code = Column(Unicode(16)) 
    title = Column(Unicode(30)) 

    #{ relations 
    intakes = relation('Intake', 
     secondary=intake_modules_table, backref='modules') 

    #{ Special methods 
    def __repr__(self): 
     return '"%s"'%self.title 
    def __unicode__(self): 
     return '"%s"'%self.title 
    #} 

가 이것을 intake_module_table에 지정된 열 duedate가 생성되지 않습니다. 여기 좀 도와주세요. 사전

답변

0

사실 열의

감사는 duedate가 생성되지만 모델을 조회 할 때 당신은 어떤 모델 속성으로하지 않습니다. 나는 Intake 대신에 intake_modules_table 테이블과 설정 관계에 대한 중간 모델을 정의해야합니다. 관계 열에 대한 액세스는 조금 더 길어질 것입니다 (module.infakes[0].duedate, module.infakes[0].infake.code). 또한 이제는 사용자가 동일한 방법으로 Infake 개체의 목록에 액세스 할 수 있도록 연결 프록시를 설정할 수 있습니다.

+0

감사합니다. buddy.will 시도해보고 결과를 알려주세요. – sam

관련 문제