Can someone tell me what Im doing wrong?? Im pulling the data from IMDBPY, everything matches but now it won't go in my tables?!
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'Movie' [SQL: INSERT INTO movie (title, "cast", plot, username) VALUES (%(title)s, %(cast)s, %(plot)s, %(username)s) RETURNING movie.id] [parameters: {'title': <Movie id:0120338[http] title: Titanic (1997) >, 'cast': <Person id:0000138[http] name: Leonardo DiCaprio >, 'plot': 'A seventeen-year-old aristocrat falls in love with a kind but poor artist aboard the luxurious, ill-fated R.MS Titanic.::j-jessie-weaver', 'username': 'plzwork'}] (Background on this error at: http://sqlalche.me/e/13/f405 )
Movies table
class Movie(db.Model):
"""movies."""
__tablename__ = "movie"
id = db.Column(db.Integer,
primary_key=True)
title = db.Column(db.String(100),
nullable=False)
cast = db.Column(db.Text)
plot = db.Column(db.Text)
username = db.Column(
db.String(20),
db.ForeignKey('users.username'),
nullable=False,
)
Adding Movies to the Database
@app.route("/users/<username>/movies/new", methods=["GET", "POST"])
def movie_show(username):
"""Show Movie Search Form and process it."""
if 'username' not in session or username != session['username']:
raise Unauthorized()
form= MovieForm()
if form.validate_on_submit():
title = form.title.data
cast= form.cast.data
plot=form.plot.data
title=moviesDB.search_movie(title)[0]
moviesDB.update(title)
cast=title['cast'][0]
moviesDB.update(title)
plot=title['plot'][0]
moviesDB.update(title)
movie = Movie(
title=(title),
cast=(cast),
plot= (plot),
username=username)
print('title', title)
print('plot', plot)
db.session.add(movie)
db.session.commit()
return redirect(f"/users/{movie.username}")
else:
return render_template("movies/new.html", form=form)
register_adapter(Movie,movie_show)
I solved this by using another API omdbapi, created a function with json to grab the data, then I called the function to update my Models.Py. Even though no one answered my question, hope this solves someone's bug:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.