As Oleg notes, your default argument call to byName is evaluated at class creation time ie, before you've created the Sales Department record. In the same way, if you had:
when = DateTimeCol(default=now()) the default would always be the value returned by now() at the time the class is imported. However, default can also be a callable. In the datetime example, changing it to: when = DateTimeCol(default=now) will cause SQLObject to call now() separately for each insert (that needs the default for this column). So as long as the Sales department is created before you actually insert any Employees, something like this should work to make that byName call lazy: def get_sales_dept(): return Department.byName('SALES') class Employee(SQLObject): user_name = UnicodeCol(alternateID=True) department = ForeignKey(default=get_sales_dept) - Luke ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss