From a6ad5ddd4b99c8aa2454ccc917f2585a1df5da0c Mon Sep 17 00:00:00 2001 From: Aditi Mittal Date: Mon, 2 Sep 2013 20:33:40 +0530 Subject: [PATCH] Make get_all_posts_of_a_blog a function of Blog class. --- mediagoblin/media_types/blog/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mediagoblin/media_types/blog/models.py b/mediagoblin/media_types/blog/models.py index a9288c00..511b41b3 100644 --- a/mediagoblin/media_types/blog/models.py +++ b/mediagoblin/media_types/blog/models.py @@ -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" -- 2.25.1