2012-03-13 28 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所以没有意识到写自己的模型管理视图和模板是多么容易。