Ignore:
Timestamp:
Oct 21, 2009 2:35:14 PM (4 years ago)
Author:
slav0nic <slav0nic0@…>
Branch:
default
Message:

fix topic removing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/forum/models.py

    r152 r153  
    217217    def delete(self, *args, **kwargs): 
    218218        self_id = self.id 
    219         head_post_id = self.topic.posts.latest().id 
     219        head_post_id = self.topic.posts.order_by('created')[0].id 
     220        forum = self.topic.forum 
     221        topic = self.topic 
    220222        self.last_topic_post.clear() 
    221223        self.last_forum_post.clear() 
    222224        super(Post, self).delete(*args, **kwargs) 
    223  
    224225        #if post was last in topic - remove topic 
    225226        if self_id == head_post_id: 
    226             self.topic.delete() 
     227            topic.delete() 
     228        else: 
     229            try: 
     230                topic.last_post = Post.objects.filter(topic=topic).latest() 
     231            except Post.DoesNotExist: 
     232                topic.last_post = None 
     233            topic.post_count = Post.objects.filter(topic=topic).count() 
     234            topic.save() 
     235        try: 
     236            forum.last_post = Post.objects.filter(topic__forum=forum).latest() 
     237        except Post.DoesNotExist: 
     238            forum.last_post = None 
     239        forum.post_count = Post.objects.filter(topic__forum=forum).count() 
     240        forum.topic_count = Topic.objects.filter(forum=forum).count() 
     241        forum.save() 
     242 
    227243 
    228244 
Note: See TracChangeset for help on using the changeset viewer.