Chapter 12.2.1. Adding Magic Attributes

To gain the benefits of the model-viewer-controller (MVC) architecture, you can’t go throwing business logic in your controller objects. Their job is to handle user actions. Wouldn’t it be convenient if you could override attribute access in your model classes? That way you could keep your controller logic clean and keep your model logic together in one obvious place. Fortunately, SQLObject makes this easy, too.

Let’s take a look at a simple example. Consider an Exam class that has simple arithmetic exercises and solutions to check against. One design is to have for each row an exercise column and a solution column. The problem with this approach is that you have to trust whoever populates this table ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.