【问题标题】:Pyramid + FormAlchemy model improvementPyramid + FormAlchemy 模型改进
【发布时间】:2012-03-13 16:23:37
【问题描述】:

我目前有两个独立的模型(如下所示),它们适用于我的小规模/测试应用程序。但是,当有超过 5000 名客户通过 FK 下拉框进行搜索时,每次输入注释时都会很烦人。

我的问题是,我是否可以将 Note 模型放入我的 Customer 模型中?这样我就可以从我的 Customer 模型中直接添加注释了吗?

#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

【问题讨论】:

    标签: python sqlalchemy pyramid formalchemy


    【解决方案1】:

    无论如何我都没有找到这样做。

    但我对金字塔和形式化学还是很陌生。

    我决定编写自己的管理/模型界面,让我可以使用金字塔视图和 jinja2 模板做我需要做的事情。不使用formalchemy和/或javascript。

    我来自 django,所以没有意识到编写自己的模型管理视图和模板是多么容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多