Le samedi 12 mai 2007 à 17:32 +0000, TiNo a écrit :
[...]
> > How does it work ?
> >
> > Regards,
> > Florent.
>
> It doesn't:
Here you are :)
Please find atached an example model.py file that works as you want...
Cheers,
Florent.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
from turbogears.database import PackageHub
from sqlobject import *
hub = PackageHub('phototest')
__connection__ = hub
class Photo(SQLObject):
class sqlmeta:
table = "photo"
filename = StringCol(length=30,alternateID=True)
keywords = RelatedJoin("Keyword", intermediateTable="photo_keyword",
joinColumn="keyword_id", otherColumn="photo_id")
def set_keywords(self, value):
'''
accepts value as a string.
Multiple keywords should be comma-seperated
'''
kwords = value.split(',')
for keyword in kwords:
keyword = keyword.strip()
try:
ref = Keyword.byKeyword(keyword)
except SQLObjectNotFound:
ref = Keyword(keyword=keyword)
self.addKeyword(ref)
class Keyword(SQLObject):
class sqlmeta:
table = "keyword"
keyword = StringCol(alternateID=True)
photos = RelatedJoin("Photo", intermediateTable="photo_keyword",
joinColumn="photo_id", otherColumn="keyword_id")