The tg2 wiki 20 tutorial (and other places) show that one adds something
along these lines to each class.
def __init__(self, pagename, data):
self.pagename = pagename
self.data = data
Why is the above done?
Is this maybe a hang over from before sql.declarative, to be able to do
the following?
aPage = model.Page(pagename='something', data='a lot of data')
If there is no other reason then I believe this is no longer needed (in
SA 0.5.7).
However I find the following useful (provided by Michael B some time
ago) in the project where I use already use SA.
class BaseExt(object):
def __repr__(self):
return "%s(%s)" % (
(self.__class__.__name__),
', '.join(["%s=%r" % (key, getattr(self, key))
for key in sorted(self.__dict__.keys())
if not key.startswith('_')]))
Base = sad.declarative_base(cls=BaseExt)
Instead of getting the following when doing a "print":
<model.Contact object at 0x020C6210>
one gets this:
Contact(address=[Address(contact=Contact(address=[...], name='a name'),
street='another street')], name='a name')
Werner
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en.