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 trial

Python Build a Social Network with Flask Broadcasting Post Form and View

Joseph Anderson
Joseph Anderson
10,617 Points

Task 3 not passing of this Lunch Order challenge.

Again I'm fairly certain I've copied the video closely. Anyway, here is what I have entered:

@app.route('/order', methods=('GET', 'POST'))
def order_lunch():
  form = forms.LunchOrderForm()
  if form.validate_on_submit():
    models.LunchOrder.new(
      order = form.order.data,
      date = form.date.data,
      user = g.user._get_current_object()
     )
  return render_template('lunch.html', form=form)

My first error was that I didn't pass the form to the template so I added in form=form to the render template line and then it just spit back out a "Bummer! Try again!"

g.user = current_user, and current_user is imported. Not sure what I'm missing here all help is appreciated, thank you!

2 Answers

Hanley Chan
Hanley Chan
27,771 Points

Hi,

To create a new LunchOrder object you should be calling models.LunchOrder.create instead of models.LunchOrder.new

@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)

Why is it .create for LunchOrder but it's .new for User?