def create_user_listing(user_id): if request.method == 'POST': listing = Listing(user_id=user_id) listing.update(request.form) db.session.add(listing) db.session.commit() users_listings_path = '/users/' + str(user_id) + '/listings' return redirect(users_listings_path)
def create_listing(): if request.method == 'POST': listing = Listing() listing.update(request.form) db.session.add(listing) db.session.commit() return redirect('/') elif request.method == 'GET': listings = Listing.query.filter(Listing.sold == False).all() json_list = {'listings': [listing.serialize for listing in listings]} return jsonify(json_list) return 'failed to create listing'