Note: This assumes that you have SQLObject installed and enabled in your web framework. Refer to your framework’s documentation for details on how to do this.
Add the following to your model file. The actual file depends on the framework:
import sqlobject as so
class Movie(so.SQLObject):
title = so.StringCol(length=100)
description = so.StringCol()
year = so.IntCol()
genera = so.StringCol(length=100)
release_date = so.DateCol()
SQLObject automatically creates an integer primary key column, called id.
When you’ve done this, you need to tell your web framework to create the database tables, see the framework-specific instructions.
In the movie controller method, replace the following lines:
# TBD: load movie from database
movie = None
With:
movie = id is not None and db.Movie.get(id)
In the save_movie controller method, replace the line:
# TBD: save movie to database
With:
movie = id is not None and db.Movie.get(id) or db.Movie()
movie.set(kw)