2012-03-13 47 views
1

我目前有兩個單獨的模型(如下所示),這對我的應用程序在小規模/測試中工作良好。但是,如果有超過5000個客戶通過FK下拉框進行搜索,每次輸入一張便箋時都會令人厭倦。金字塔+ FormAlchemy模型改進

我的問題是,無論如何,我可以把筆記模型放在我的客戶模型裏面嗎?所以從我的客戶模型中,我可以直接添加筆記?

#models.py 
samples_to_customer = Table('samples_to_customer', Base.metadata, 
    Column('customer_id', Integer, ForeignKey('customer.id')), 
    Column('sample_id', Integer, ForeignKey('samples.id')) 
) 

#Create a cusotmer model to store customer numbers 

class Customer(Base): 
    __tablename__ = 'customer' 
    __acl__ = [ 
      (Allow, 'admin', ALL_PERMISSIONS), 
      (Allow, 'saff', ('view', 'edit')), 
     ] 
    id = Column(Integer, primary_key=True) 
    name = Column(Unicode, unique=True) #this will be the variable used to search the existing db 
    customer_samples = relationship('Sample', secondary='samples_to_customer', backref='samples') 
    sales_rep = Column(Integer, ForeignKey('rep.id')) 
    rep = relationship('Rep', backref='rep') 

    def __unicode__(self): 
     return self.name 

# This model will have its own entry view/page a user logs on and enters notes (according to a customer 
# number) they then get stored/saved onto the Customers account 
class Note(Base): 
    __tablename__ = 'note' 
    __acl__ = [ 
      (Allow, 'admin', ALL_PERMISSIONS), 
      (Allow, 'staff', ('view', 'edit')), 
     ]  
    id = Column(Integer, primary_key=True) 
    name = Column(Unicode) 
    pub_date = Column(Date) 
    customer_no = Column(Integer, ForeignKey('customer.id')) 
    customer = relationship('Customer', backref='notes') 

    def __unicode__(self): 
     return self.name 

回答

1

我沒有找到任何辦法todo這個。

但是我對金字塔和形式學仍然很陌生。

我決定寫我自己的管理員/模型界面,讓我做我需要的金字塔視圖和jinja2模板。沒有使用formalchemy和或javascript。

我來自django所以沒有意識到寫自己的模型管理視圖和模板是多麼容易。