diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2011-12-31 23:01:34 +0100 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-01-11 12:19:03 +0100 |
commit | 02db7e0a83fc06eaa8e96888f6c9e4fb44e7cbe2 (patch) | |
tree | 04bc7ee1b47416771f37abb759d9895b995744dc /mediagoblin/db/sql/models.py | |
parent | 0ab21f981a8a170f5bf4e83f7d56d3ed8fdae467 (diff) | |
download | mediagoblin-02db7e0a83fc06eaa8e96888f6c9e4fb44e7cbe2.tar.lz mediagoblin-02db7e0a83fc06eaa8e96888f6c9e4fb44e7cbe2.tar.xz mediagoblin-02db7e0a83fc06eaa8e96888f6c9e4fb44e7cbe2.zip |
Add MediaFile table and related infrastructure.
- This adds a new SQL table field type for path tuples.
They're stored as '/' separated unicode strings.
- Uses it to implement a MediaFile table.
- Add relationship and proxy fields on MediaEntry to give a
nice media_files "view" there.
- Let the converter fill the MediaFile.
Diffstat (limited to 'mediagoblin/db/sql/models.py')
-rw-r--r-- | mediagoblin/db/sql/models.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 95821b4f..91092f33 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -5,7 +5,10 @@ from sqlalchemy import ( Column, Integer, Unicode, UnicodeText, DateTime, Boolean, ForeignKey, UniqueConstraint) from sqlalchemy.orm import relationship +from sqlalchemy.orm.collections import attribute_mapped_collection +from sqlalchemy.ext.associationproxy import association_proxy +from mediagoblin.db.sql.extratypes import PathTupleWithSlashes from mediagoblin.db.sql.base import GMGTableBase from mediagoblin.db.mixin import UserMixin, MediaEntryMixin @@ -65,7 +68,7 @@ class MediaEntry(Base, MediaEntryMixin): fail_error = Column(Unicode) fail_metadata = Column(UnicodeText) - queued_media_file = Column(Unicode) + queued_media_file = Column(PathTupleWithSlashes) queued_task_id = Column(Unicode) @@ -75,13 +78,33 @@ class MediaEntry(Base, MediaEntryMixin): get_uploader = relationship(User) + media_files_helper = relationship("MediaFile", + collection_class=attribute_mapped_collection("name"), + cascade="all, delete-orphan" + ) + media_files = association_proxy('media_files_helper', 'file_path', + creator=lambda k,v: MediaFile(name=k, file_path=v) + ) + ## TODO - # media_files # media_data # attachment_files # fail_error +class MediaFile(Base): + __tablename__ = "mediafiles" + + media_entry = Column( + Integer, ForeignKey(MediaEntry.id), + nullable=False, primary_key=True) + name = Column(Unicode, primary_key=True) + file_path = Column(PathTupleWithSlashes) + + def __repr__(self): + return "<MediaFile %s: %r>" % (self.name, self.file_path) + + class Tag(Base): __tablename__ = "tags" |