Skip to content

Instantly share code, notes, and snippets.

@e000
Created March 13, 2011 22:59
Show Gist options
  • Select an option

  • Save e000/868525 to your computer and use it in GitHub Desktop.

Select an option

Save e000/868525 to your computer and use it in GitHub Desktop.
>>> Image.query.filter(Image.name.contains('jpg')).first()
<Image #1 [CONTEXT177.jpg] @ [/media/truecrypt1/Pictures/CONTEXT177.jpg] in <Folder #1 [Unfiled, 13649 items]>>
>>> img = _
>>> img.tags
[<Tag u''>]
>>> # empty tag
...
>>> from models import getTag
>>> img.tags[:] = []
>>> img.tags
[]
>>> img.tags.append(getTag('funny'))
>>> img.tags.append(getTag('test tag'))
>>> img.tags
[<Tag u'funny'>, <Tag 'test tag'>]
>>> db.session.commit()
>>> t = getTag('test tag')
>>> t.images
<sqlalchemy.orm.dynamic.AppenderQuery object at 0xa31aa2c>
>>> t.images.all()
[<Image #1 [CONTEXT177.jpg] @ [/media/truecrypt1/Pictures/CONTEXT177.jpg] in <Folder #1 [Unfiled, 13649 items]>>]
>>> t.images.first().tags
[<Tag u'funny'>, <Tag u'test tag'>]
>>> from app import Folder
>>> f = Folder('Funny')
>>> f.id is None
True
>>> db.session.add(f)
>>> db.session.commit()
>>> f.id
4
>>> Folder.query.get(4) is f
True
>>> f.name
u'Funny'
>>> f.images.all()
[]
>>> img.folder = f
>>> db.session.commit()
>>> f.images.all()
[<Image #1 [CONTEXT177.jpg] @ [/media/truecrypt1/Pictures/CONTEXT177.jpg] in <Folder #4 [Funny, 1 items]>>]
>>> img
<Image #1 [CONTEXT177.jpg] @ [/media/truecrypt1/Pictures/CONTEXT177.jpg] in <Folder #4 [Funny, 1 items]>>
>>> img.tags
[<Tag u'funny'>, <Tag u'test tag'>]
>>> db.session.delete(f)
>>> db.session.commit()
>>> img.folder is None
True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment