Adding code from chapter 7 of Tango With Django