diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-02-25 23:53:11 +0100 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-02-28 20:52:35 +0100 |
commit | 3502958113c09c80830b7bee63c3d82b5ff72eb9 (patch) | |
tree | ae5037d788612b6822791cf8e2b6ba279ff2e475 /mediagoblin/db/sql/models.py | |
parent | e9f87f728ce67467272d9484b711e2a518537cb4 (diff) | |
download | mediagoblin-3502958113c09c80830b7bee63c3d82b5ff72eb9.tar.lz mediagoblin-3502958113c09c80830b7bee63c3d82b5ff72eb9.tar.xz mediagoblin-3502958113c09c80830b7bee63c3d82b5ff72eb9.zip |
Attachment support in the SQL backend
attachments working with the sql backend.
- SQL Schema for attachment files, ordering attachments by
their name, not by the submission order (as earlier).
- Dot-Notation for attachments, where missing.
- convert existing attachments over from mongo -> sql
Diffstat (limited to 'mediagoblin/db/sql/models.py')
-rw-r--r-- | mediagoblin/db/sql/models.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 699dbf33..b52eac76 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -118,6 +118,15 @@ class MediaEntry(Base, MediaEntryMixin): creator=lambda k, v: MediaFile(name=k, file_path=v) ) + attachment_files_helper = relationship("MediaAttachmentFile", + cascade="all, delete-orphan", + order_by="MediaAttachmentFile.created" + ) + attachment_files = association_proxy("attachment_files_helper", "dict_view", + creator=lambda v: MediaAttachmentFile( + name=v["name"], filepath=v["filepath"]) + ) + tags_helper = relationship("MediaTag", cascade="all, delete-orphan" ) @@ -127,7 +136,6 @@ class MediaEntry(Base, MediaEntryMixin): ## TODO # media_data - # attachment_files # fail_error _id = SimpleFieldAlias("id") @@ -177,6 +185,23 @@ class MediaFile(Base): return "<MediaFile %s: %r>" % (self.name, self.file_path) +class MediaAttachmentFile(Base): + __tablename__ = "core__attachment_files" + + id = Column(Integer, primary_key=True) + media_entry = Column( + Integer, ForeignKey(MediaEntry.id), + nullable=False) + name = Column(Unicode, nullable=False) + filepath = Column(PathTupleWithSlashes) + created = Column(DateTime, nullable=False, default=datetime.datetime.now) + + @property + def dict_view(self): + """A dict like view on this object""" + return DictReadAttrProxy(self) + + class Tag(Base): __tablename__ = "tags" |