Create a fully functional get_comments for SQL
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Mon, 2 Jan 2012 12:07:16 +0000 (13:07 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Sun, 22 Jan 2012 17:40:42 +0000 (18:40 +0100)
Using proper sqlalchemy syntax instead of the emulated
mongo one.

mediagoblin/db/sql/models.py

index 507efe622dec4d57add69acd7beca9c3ba826f12..d5573a56a2e3d6a4813c5e27771a69cc2f45ba23 100644 (file)
@@ -109,6 +109,13 @@ class MediaEntry(Base, MediaEntryMixin):
     # attachment_files
     # fail_error
 
+    def get_comments(self, ascending=False):
+        order_col = MediaComment.created
+        if not ascending:
+            order_col = desc(order_col)
+        return MediaComment.query.filter_by(
+            media_entry=self.id).order_by(order_col)
+
 
 class MediaFile(Base):
     __tablename__ = "mediafiles"