wiki:ForeignKeysInFastData
Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 1 (modified by tlesher@…, 13 years ago) (diff)

Added

Suppose you have a model that looks like this:

class Employee(SQLObject):
   name = StringCol(length=40, alternateID=True, title="Name")
   department = ForeignKey('Department')

class Department(SQLObject):
   number = IntCol(alternateID=True, title="Department Number")
   name = StringCol(length=40, alternateID=True, title="Department Name")

If you use FastData to display an Employee's Department in a grid, the Department will show up like this:

< Department number=123, name="Accounting" ... >

What you're seeing is the output from SQLObject's default __str__ method. To make this more readable, override that method:

class Department(SQLObject):
   number = IntCol(alternateID=True, title="Department Number")
   name = StringCol(length=40, alternateID=True, title="Department Name")
 
   def __str__(self):
      return "%d (%s)" % (self.number, self.name)

Now, whenever you display the Department as a ForeignKey, you will see:

123 (Accounting)