From caeab88f883d6c0390d796ef56a89fee61fb4432 Mon Sep 17 00:00:00 2001 From: Aditi Mittal Date: Mon, 9 Sep 2013 21:48:02 +0530 Subject: [PATCH] Write code for deleting a blog --- mediagoblin/media_types/blog/models.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) 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" -- 2.25.1