Hi all,
I'm implementing a tagging system for a site I'm working on. A
registered user can tag a page, and I need to be able to track which
users tagged which pages with which tag. I also need to be able to
easily count the number of users who tagged a recipe with a certain tag,
and how many recipes a user has tagged with a certain tag (for
generating tag clouds, etc -- hence SQLRelatedJoin below rather than
RelatedJoin).
My model looks something like this:
#---------------------------------------------------------------------
class User(SQLObject):
class sqlmeta: table = 'tg_user' # Turbogears project
...
tags = SQLRelatedJoin('Tag', intermediateTable="tag_users",
joinColumn='user_id', otherColumn='tag_id')
class Tag(SQLObject):
name = UnicodeCol(alternateID=True)
pages = SQLRelatedJoin('Page', intermediateTable='page_tags',
joinColumn='tag_id', otherColumn='page_id')
users = SQLRelatedJoin('User', intermediateTable='tag_users',
joinColumn='tag_id', otherColumn='user_id')
class Page(SQLObject):
...
tags = SQLRelatedJoin('Tag', intermediateTable='page_tags',
joinColumn='page_id', otherColumn='tag_id')
#---------------------------------------------------------------------
I'm coming across difficulty while trying to find out which tags a user
has used for a particular page. At the moment I've had to resort to the
following code, but I'm sure this should be possible as a pure select()
statement or similar.
# page and user are instances of Page and User respectively.
userstags = filter(
lambda tag: page in tag.pages,
user.tags.distinct().orderBy(Tag.q.name)
)
Thanks and regards,
Nick Murdoch
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss