python - Pyramid + FormAlchemy 模型改进

标签 python sqlalchemy pyramid formalchemy

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

我的问题是,我是否可以将 Note 模型放入我的 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

最佳答案

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

但我对 Pyramid 和形式化学还很陌生。

我决定编写自己的管理/模型界面,它让我可以使用 Pyramid View 和 jinja2 模板完成我需要做的事情。不使用formalchemy和/或javascript。

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

关于python - Pyramid + FormAlchemy 模型改进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9687956/

相关文章:

python - 如何根据其他列表中的项目匹配来选择子列表中的外部项目?

python - 如何解决:“UnicodeDecodeError:'ascii'编解码器无法解码字节”

python - 将数据帧写入mysql数据库

python - Pyramid - 为文件上传表单编写单元测试

python - 未找到“pyramid-debugtoolbar”分布并且是必需的

python - Pyramid 1.3 和 Google App Engine 1.7

python - 排序索引满足一定条件的数据框

python - 如何在 modbus 寄存器中存储带符号的 16 位值

python - 在 Ubuntu 12.04 上使用 SQLAlchemy 查询时出现类型错误,但在 Windows 上则不然

postgresql - 如何使用 SQLAlchemy 将列默认设置为 PostgreSQL 函数?