From: Elrond Date: Sat, 24 Dec 2011 15:00:05 +0000 (+0100) Subject: SQL Model: Add relationship properties X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=88e90f41eb86b8aa1fcfef1e0585f314afb5180d;p=mediagoblin.git 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. --- 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