Reputation: 908
I currently have two separate models (shown below), which works fine for my application in small scale/testing. However when there are over 5000 customers searching via a FK dropdown box will be tiresome each time a note is inputted.
My question is, is there anyway I could put the Note model inside of my Customer model? So that from inside my Customer model I could add notes directly?
#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
Upvotes: 1
Views: 467
Reputation: 908
I didnt find anyway todo this.
But I am still very new to pyramid and formalchemy.
I have decided to write my own admin/model interface which let me do what I needed to with pyramid views and jinja2 templates. Without using formalchemy and or javascript.
I am coming from django so didnt realise just how easy it was to write my own model admin views and templates.
Upvotes: 1