Last active
December 10, 2015 04:28
-
-
Save joar/4381694 to your computer and use it in GitHub Desktop.
modifying mediagoblin MediaEntries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # (c) 2012 Joar Wandborg <http://wandborg.se> | |
| # Licensed under CC0 (http://creativecommons.org/publicdomain/zero/1.0/) | |
| # | |
| # This is an interactive session from `gmg shell` | |
| # Query the database for some MediaEntries | |
| m = db.MediaEntry.query.filter(db.MediaEntry.id > 2, db.MediaEntry.id <= 4).all() | |
| for entry in m: | |
| print entry.tags # List all tags | |
| for entry in m: | |
| entry.tags = [{'name': 'Foo', 'slug':'foo'}, {'name': 'bar', 'slug': 'bar'}] # Set the tags | |
| entry.title = u'HaxHax!' | |
| entry.save() # Save the changes to the database |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # (c) 2012 Joar Wandborg <http://wandborg.se> | |
| # Licensed under CC0 (http://creativecommons.org/publicdomain/zero/1.0/) | |
| # | |
| # Standalone script that interacts with GNU MediaGoblin | |
| from mediagoblin import mg_globals | |
| from mediagoblin import app | |
| MEDIAGOBLIN_CONFIG = 'mediagoblin_local.ini' | |
| mg_app = app.MediaGoblinApp(MEDIAGOBLIN_CONFIG) | |
| db = mg_globals.database | |
| entries = db.MediaEntry.query.filter(db.MediaEntry.title == u'badtitle').all() | |
| for entry in entries: | |
| print entry.title | |
| # [...] | |
| entry.save() # Save changes to the DB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment