On Tue, May 15, 2007 at 01:07:14AM +0200, TiNo wrote:
> Hi,
>
> I have a db model that looks like this:
> class Photo(SQLObject):
> filename = StringCol(length=30,alternateID=True)
> keywords = RelatedJoin("Keyword")
> shot_date = DateTimeCol(default=None)
> place = StringCol(default=None)
>
> class Keyword(SQLObject):
> keyword = StringCol(alternateID=True)
> photos = RelatedJoin("Photo")
>
> Two questions:
>
> 1) How do I select all photos that have keyword1 AND keyword2?
photos = []
for photo on Photo.select():
found = 0
for keyword in photo.keywords:
if keyword.keyword in ("test1", "TeSt2"):
found += 1
if found == 2:
photos.append(photo)
> 2) What is the easiest way to build up a long select?
conditions = []
if date:
conditions.append(Photo.q.shotdate == date)
if place:
conditions.append(Photo.q.place == place)
Photo.select(AND(*conditions))
Don't forget * in *conditions!
Oleg.
--
Oleg Broytmann http://phd.pp.ru/ [EMAIL PROTECTED]
Programmers don't die, they just GOSUB without RETURN.
-------------------------------------------------------------------------
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