Make get_all_posts_of_a_blog a function of Blog class.
authorAditi Mittal <aditi.iitr@gmail.com>
Mon, 2 Sep 2013 15:03:40 +0000 (20:33 +0530)
committerAditi Mittal <aditi.iitr@gmail.com>
Mon, 2 Sep 2013 15:03:40 +0000 (20:33 +0530)
mediagoblin/media_types/blog/models.py

index a9288c00abc53df2c8a86a52ff2b54361d57163a..511b41b33e0be5fbd2b2a31b8f5eab024092bf6c 100644 (file)
@@ -17,6 +17,7 @@
 import datetime
 
 from mediagoblin.db.base import Base
+from mediagoblin.db.base import Session
 from mediagoblin.db.models import Collection, User, MediaEntry
 from mediagoblin.db.mixin import GenerateSlugMixin
 
@@ -41,6 +42,13 @@ class Blog(Base, BlogMixin):
     author = Column(Integer, ForeignKey(User.id), nullable=False, index=True) #similar to uploader
     created = Column(DateTime, nullable=False, default=datetime.datetime.now, index=True)
     slug = Column(Unicode)
+    
+    def get_all_posts_of_a_blog(self, state=None):
+               blog_posts = Session.query(MediaEntry).join(BlogPostData)\
+               .filter(BlogPostData.blog == self.id)
+               if state is not None:
+                       blog_posts = blog_posts.filter(MediaEntry.state==state)
+               return blog_posts
 
     
 BACKREF_NAME = "blogpost__media_data"