I chose to create this simple model by hand. The code seen below is amazingly short. It is enough to handle CRUD-operations for all objects. It also does some magic middle table for the many-to-many relation between Action and Tag (I haven’t tested this yet though).
I am a big fan of testing. A unit test coverage below 70% gives me the creeps. But in this case, what should I test? I trust generated code. If I would have done this with Hibernate or iBatis, I would have written a bunch of test cases for it, simply because I don’t trust the amount of code and configurations lying around. But in this case it feels unnecessary to write any tests for the model. This saves a lot of time. Time will show if this was a wise thing to do.
model.py:
from sqlobject import *
from datetime import datetime
from turbogears.database import PackageHub
from turbogears.identity.soprovider import
TG_User, TG_Group, TG_Permission
hub = PackageHub("turbogtd")
__connection__ = hub
class Project(SQLObject):
title = UnicodeCol(notNone=True)
notes = UnicodeCol()
actions = MultipleJoin("Action")
class Action(SQLObject):
title = UnicodeCol(notNone=True)
notes = UnicodeCol()
project = ForeignKey("Project")
context = ForeignKey("Context")
tags = RelatedJoin("Tag")
class Tag(SQLObject):
title = UnicodeCol(notNone=True, alternateID=True)
actions = RelatedJoin("Action")
class Context(SQLObject):
title = UnicodeCol(notNone=True, alternateID=True)
[...] model.py (compare to SQLObject version. Note that I’ve added some columns not shown in the previous model): [...]