From: Aditi Mittal Date: Mon, 9 Sep 2013 16:18:02 +0000 (+0530) Subject: Write code for deleting a blog X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=caeab88f883d6c0390d796ef56a89fee61fb4432;p=mediagoblin.git Write code for deleting a blog --- diff --git a/mediagoblin/media_types/blog/models.py b/mediagoblin/media_types/blog/models.py index 5a6da19e..7c55e359 100644 --- a/mediagoblin/media_types/blog/models.py +++ b/mediagoblin/media_types/blog/models.py @@ -43,13 +43,24 @@ class Blog(Base, BlogMixin): created = Column(DateTime, nullable=False, default=datetime.datetime.now, index=True) slug = Column(Unicode) + def get_all_blog_posts(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 - + 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 + + def delete(self, **kwargs): + all_posts = self.get_all_blog_posts() + for post in all_posts: + post.delete(del_orphan_tags=False, commit=False) + from mediagoblin.db.util import clean_orphan_tags + clean_orphan_tags(commit=False) + super(Blog, self).delete(**kwargs) + + + BACKREF_NAME = "blogpost__media_data"