Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBoris Kowalski
13,589 PointsLunch order form, Challenge Task 3 of 3: Finally, you need to instantiate, process, and send LunchOrde
In the last stage of the challenge I use this code in lunch.py. It does not work i already came back to the challenge after a while and rewrote the code for it but I can not advance here.
@app.route('/order', methods=('GET', 'POST'))
def order_lunch():
form = forms.LunchOrderForm()
if form.validate_on_submit():
models.Order(
order = form.order.data,
date = form.date.data,
user = current_user
)
return render_template('lunch.html', form=form)
Where sits the error?
1 Answer
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Boris You need to create an instance of the LunchOrder model, you are calling a model called order??. You also need to call the create method on the model to create a new instance. I always used g.user._get_current_object() because assigning g.user to current_user never worked for me, may be someone else encountered this and solved it. Try the code below it should pass.
@app.route('/order', methods=('GET', 'POST'))
def order_lunch():
form = forms.LunchOrderForm()
if form.validate_on_submit():
models.LunchOrder.create(
order = form.order.data,
date = form.date.data,
user = g.user._get_current_object()
)
return render_template('lunch.html',form=form)
hope this helps
Boris Kowalski
13,589 PointsBoris Kowalski
13,589 PointsThanks Andreas, that was it. After i posted the question and looking the next few videos i stumbled upon the create method and tried it directly. But it did not work.
It would be nice when someone could tell the difference between the not working current_user and g.user._get_current_object