my identity provider:
http://projectsmgt.opensource4you.org/ProjectsMgt/file/trunk/projectsmgt/model.py
This way you can design your Users db as you want.
Don't forget to update accordingly the .cfg (
http://projectsmgt.opensource4you.org/ProjectsMgt/file/trunk/dev.cfg)
Maybe not the best method, but very flexible.
William
from turbogears.identity.model.somodel import User
class myUser(SQLObject):
fk_to_user = IntCol()
def _get_user(self):
return User.get(self.fk_to_user)
def _set_user(self, user_obj):
self.fk_to_user = user_obj.id
def _del_user(self):
u=User.get(self.fk_to_user)
u.destroySelf()
self.fk_to_user = None
# Other things you want to implement in your class...
Unless SQLObject defines a way to access other registry classes (which
I couldn't find), I think that's your simplest solution. If your
database supports it, it may be worthwhile to set up the foreign key
reference in your db schema, just to be sure.
#get the identity user
u = User(1)
#create myUser
mu=myUser(fk_to_user=None)
mu.user=u
# can now reference the attributes of the user through mu
email = mu.user.emailAddress
But I think that putting TG models in a different registry makes it
unnessesarily difficult, unless SQLObject has some magic function to
change it... Maybe a better way will be just use "TG" prefix for
TurboGear models? The tables have tg_ prefix anyway...
--
Jeff Watkins
Computers, they're just a fad.
class Foo(SQLObject):
class sqlmeta:
registry='foo'
name = StringCol(length=50)
class Bar(SQLObject):
foo_obj = ForeignKey('foo.Foo')
While this appears to work, as soon as you try to reference
Bar.foo_obj, an exception is thrown.
Traceback (most recent call last):
File "<console>", line 1, in ?
File "<string>", line 1, in <lambda>
AttributeError: 'Bar' object has no attribute '_SO_class_foo'
I imagine subcassing is a pain too, because your subclass is
automatically in the parent's registry, and can't refer to your
applications registry.
If you can't refer to another registry, I guess I don't really see the
point of it (I was unaware this was how the registry worked, too).
Sure, it prevents namespace clashes, but interoperability between
classes would seem to be pretty important. I'm hoping this is just a
lack of understanding on my part.
Perhaps this is a question that should be asked on the SQLObject list?
I've found the following works:
from sqlobject import *
from turbogears.identity.model import somodel
class Report(SQLObject):
title = StringCol()
user = ForeignKey("User")
_SO_class_User = somodel.User
This does not work with Catwalk, I get an alert saying "Fail to get
reference to object User" if I click on the Report table.
It seems that the most instinctive way would be to have user =
ForeignKey("turbogears.User") but we'll see how future versions of
SQLObject will resolve this.