python - error message : InterfaceError: <unprintable InterfaceError object> -


linking 2 tables , trying create form foreign key in it.

sqlalchemy.exc.interfaceerror

interfaceerror: unprintable interfaceerror object

datbase link done :

class client(db.model): __tablename__ = 'client' .. stand_id = db.column(db.string(10), index = true, unique = true) stands = db.relationship('stand', backref= 'stand', lazy='select')   def __init__(self,client_name,contact_number,contact_name,contact_email,stand_id):     self.client_name = client_name     self.contact_number = contact_number     self.contact_email = contact_email     self.contact_name = contact_name     self.stand_id = stand_id   class stand(db.model): __tablename__ = 'stand' .. stand_number = db.column(db.string(10), db.foreignkey('client.stand_id' ))   def __repr__(self):     return '<stand %r>' % (self.stand_id)   def __init__(self, stand_name,items, quantity,install_date,  derig_date,comments,last_update, stand_number):  self.stand_name = stand_name  self.items = items  self.quantity = quantity   self.install_date = install_date  self.derig_date =  derig_date  self.comments = comments  self.last_update = last_update  self.stand_number = stand_number 

form

class standform(form):  stand_name =  textfield('stand_name', validators = [required()])  items = textareafield('items', validators = [required()]) quantity = textareafield('quantity', validators = [required()]) install_date = textfield('install_date',validators = [required()]) derig_date = textfield('derig_date', validators = [required()]) comments = textfield('comments', validators = [required()]) last_update = textfield('last_update', validators = [required()]) stand_number = queryselectfield(query_factory=lambda: client.query.all()) 

and view

@app.route('/newstand', methods = ['get','post']) def newstand():   form = standform()  if form.validate():      stand = stand(      request.form['stand_name'], request.form['items'], request.form['quantity'],       request.form['install_date'],request.form['derig_date'], request.form['comments'],       request.form['last_update'], request.form['stand_number'])     form.populate_obj(stand)      db.session.add(stand)     db.session.commit()      return render_template('liststands.html',          stand = stand,           form=form)   else:     flash("your form contained errors")  return render_template('newstand.html', form = form 

i don't think have written function quite right, opinions/help ?

i ran same error, , looks might similar problem. queryselectfield returns complete object, not id. above example:

rename form field reflect contains:

class standform(form):   ...   stand = queryselectfield(query_factory=lambda: client.query.all()) 

and use id when constructing object in view:

@app.route('/newstand', methods = ['get','post']) def newstand():    form = standform()   if form.validate():      stand = stand(       request.form['stand_name'], request.form['items'], request.form['quantity'],        request.form['install_date'],request.form['derig_date'], request.form['comments'],        request.form['last_update'], request.form['stand'].stand_id)     ... 

also, above example both constructing stand object form contents explicitly, , again calling form.populate_obj, redundant (it populate same fields on object again), 1 of these can removed.

if form.populate_obj automatically respects foreign keys (which i'd assume does, though haven't tried it), can simplify view code to:

@app.route('/newstand', methods = ['get','post']) def newstand():    form = standform()   if form.validate():      stand = stand()     form.populate_obj(stand)     ... 

Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -