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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user