def edExpense(id): ''' only called with a url link ''' expData=Expense.query.filter_by(id=id).first() #make form and assign default values form=forms.addExpenseForm(title=expData.title,entVal=expData.value,eDate=expData.date,account=expData.account_id) form.account.choices=[(acc.id,acc.title) for acc in Account.query.order_by('title')] if form.validate_on_submit(): expData.title=form.title.data expData.value=form.entVal.data expData.entDate=form.eDate.data expData.account_id=form.account.data db.session.add(expData) db.session.commit() flash("Expense %s Edit Success!"%expData.title) return redirect(url_for('welcome')) return render_template('budg_Expense.html',expData=expData, form=form,expAdd="edit")
def adExpense(): '''add a single expense to an account''' form=forms.addExpenseForm() #set up theform form.account.choices=[(acc.id,acc.title) for acc in Account.query.order_by('title')] if form.validate_on_submit(): #if the form data is validated create_a_thing(Expense,[form.account.data,form.title.data,form.entVal.data,form.eDate.data]) return redirect(url_for('welcome')) #send in the accounts to populate the dropdown menu return render_template('budg_Expense.html',form=form,edAdd="add")