.. _db_tg2: TurboGears 2 ============ In the controller, import the model with the prefix db. Add this to the top of ``myapp/controllers/root.py``:: import myapp.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.html``, 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. Change the method to:: def save_movie(self, id, **kw): if request.method != 'POST': raise Exception('save_movie must be a POST request') # TBD: save movie to database return "Movie successfully saved" Model Details ------------- You'll need to create a new file for your model, I suggest ``myapp/model/main.py``. Then in ``myapp/model/__init__.py``, add at the end:: from main import * To create the database tables defined in your model, issue:: $ paster setup-app development.ini Using Elixir ------------ You need to add the following line to the top of ``myapp/model/main.py``:: from myapp.model import metadata as __metadata__, DBSession as __session__