diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2011-12-24 16:00:05 +0100 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2011-12-28 22:58:44 +0100 |
commit | 88e90f41eb86b8aa1fcfef1e0585f314afb5180d (patch) | |
tree | c0870e0ad1f7d6784867f368baecf8fc07af85af /mediagoblin/db/sql/models.py | |
parent | c6263400cfd334a820122bd1b22eaa4d4d6765cd (diff) | |
download | mediagoblin-88e90f41eb86b8aa1fcfef1e0585f314afb5180d.tar.lz mediagoblin-88e90f41eb86b8aa1fcfef1e0585f314afb5180d.tar.xz mediagoblin-88e90f41eb86b8aa1fcfef1e0585f314afb5180d.zip |
SQL Model: Add relationship properties
MediaEntry now has a get_uploader (property) loading the
appropiate User object for the MediaEntry (and caches it).
MediaComment has the same for author as get_author.
Diffstat (limited to 'mediagoblin/db/sql/models.py')
-rw-r--r-- | mediagoblin/db/sql/models.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 268f5715..31a6ed3b 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -4,6 +4,7 @@ from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import ( Column, Integer, Unicode, UnicodeText, DateTime, Boolean, ForeignKey, UniqueConstraint) +from sqlalchemy.orm import relationship from mediagoblin.db.sql.base import GMGTableBase @@ -71,6 +72,8 @@ class MediaEntry(Base): UniqueConstraint('uploader', 'slug'), {}) + get_uploader = relationship(User) + ## TODO # media_files # media_data @@ -112,6 +115,8 @@ class MediaComment(Base): content = Column(UnicodeText, nullable=False) content_html = Column(UnicodeText) + get_author = relationship(User) + def show_table_init(): from sqlalchemy import create_engine |