from flask import Flask, request, render_template from models import db, ModelForm, BondDeal, Counterparties import pdb app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://dawn_user@debian/dawndb' app.config['SECRET_KEY'] = 'papa' db.init_app(app) def list_counterparties(): return Counterparties.query.order_by('name').\ with_entities(Counterparties.code, Counterparties.name) # Base.metadata.create_all(engine) class BondForm(ModelForm): class Meta: model = BondDeal include_foreign_keys = True @app.route('/', methods=['GET', 'POST']) def trade_entry(): bond_form = BondForm() bond_form.counterparty.choices = list_counterparties() if bond_form.is_submitted(): if bond_form.validate(): bond = BondDeal() bond_form.populate_obj(bond) bond.dealid = 'uniqid' db.session.add(bond) db.session.commit() return "Success!" else: print(bond_form.errors) return render_template("trade_entry.html", form=bond_form) if __name__=="__main__": app.run(debug=True)