.. _db_tg1: TurboGears 1 ============ In the controller, import the model with the prefix db. Add this to the top of ``myapp/controllers.py``:: import model as db We need to update the ``movie`` method to accept an ``id`` parameter, and to pass the loaded database object to the template. Change the method to:: def movie(self, id=None, **kw): # TBD: load movie from database movie = None return dict(movie_form=movie_form, movie=movie) And update the template ``myapp/templates/movie.kid``, so the widget is called like this:: ${movie_form(movie)} We need to update the ``save_movie`` method to check that the request is a POST request. We'll also change the response to inform the user the movie has been saved. Add this to the top of the file:: import cherrypy as cp And change the ``save_movie`` method to:: def save_movie(self, id, **kw): if cp.request.method != 'POST': raise Exception('save_movie must be a POST request') # TBD: save movie to database return "Movie successfully saved" Model Details ------------- The model file is ``myapp/model.py``. To create the database tables defined in your model, issue:: $ tg-admin sql create