From 88e90f41eb86b8aa1fcfef1e0585f314afb5180d Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 24 Dec 2011 16:00:05 +0100 Subject: [PATCH] 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. --- mediagoblin/db/sql/models.py | 5 +++++ 1 file changed, 5 insertions(+) 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 -- 2.25.1