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

Changes between Version 1 and Version 2 of ForeignKeysInFastData


Ignore:
Timestamp:
06/29/07 10:22:40 (12 years ago)
Author:
Chris Arndt
Comment:

migration notice

Legend:

Unmodified
Added
Removed
Modified
  • ForeignKeysInFastData

    v1 v2  
    1 Suppose you have a model that looks like this: 
    21{{{ 
    3 #!python 
    4  
    5 class Employee(SQLObject): 
    6    name = StringCol(length=40, alternateID=True, title="Name") 
    7    department = ForeignKey('Department') 
    8  
    9 class Department(SQLObject): 
    10    number = IntCol(alternateID=True, title="Department Number") 
    11    name = StringCol(length=40, alternateID=True, title="Department Name") 
     2#!rst 
     3.. note:: This page has been migrated to http://docs.turbogears.org/1.0/ForeignKeysInFastData. 
    124}}} 
    13  
    14 If you use !FastData to display an Employee's Department in a grid, the Department will show up like this: 
    15  
    16 {{{ 
    17 < Department number=123, name="Accounting" ... > 
    18 }}} 
    19  
    20 What you're seeing is the output from SQLObject's default !__str!__ method. To make this more readable, override that method: 
    21  
    22 {{{ 
    23 #!python 
    24  
    25 class Department(SQLObject): 
    26    number = IntCol(alternateID=True, title="Department Number") 
    27    name = StringCol(length=40, alternateID=True, title="Department Name") 
    28   
    29    def __str__(self): 
    30       return "%d (%s)" % (self.number, self.name) 
    31 }}} 
    32  
    33 Now, whenever you display the Department as a !ForeignKey, you will see: 
    34  
    35 {{{ 
    36 123 (Accounting) 
    37 }}}