私は現在、2 つの別々のモデル (以下に示す) を持っています。これは、小規模/テストのアプリケーションでは問題なく動作します。ただし、FK ドロップダウン ボックスを介して検索する 5000 人を超える顧客がいる場合、メモを入力するたびに面倒になります。
私の質問は、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