From: Aditi Mittal Date: Mon, 2 Sep 2013 15:03:40 +0000 (+0530) Subject: Make get_all_posts_of_a_blog a function of Blog class. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a6ad5ddd4b99c8aa2454ccc917f2585a1df5da0c;p=mediagoblin.git Make get_all_posts_of_a_blog a function of Blog class. --- 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"