Write code for deleting a blog
authorAditi Mittal <aditi.iitr@gmail.com>
Mon, 9 Sep 2013 16:18:02 +0000 (21:48 +0530)
committerAditi Mittal <aditi.iitr@gmail.com>
Mon, 9 Sep 2013 16:18:02 +0000 (21:48 +0530)
mediagoblin/media_types/blog/models.py

index 5a6da19eafde6247287696768185bf98a557775c..7c55e359a60342597d32ac2dba1ad3c8ddf69fe5 100644 (file)
@@ -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"