Changeset 352:d13220c8831b


Ignore:
Timestamp:
16.05.2011 11:40:54 (12 months ago)
Author:
slav0nic <slav0nic0@…>
Branch:
default
Message:

fix #87: topic deleting droped forum in cascade

File:
1 edited

Legend:

Unmodified
Added
Removed
  • djangobb/djangobb_forum/models.py

    r323 r352  
    130130    class Meta: 
    131131        ordering = ['-updated'] 
     132        get_latest_by = 'updated' 
    132133        verbose_name = _('Topic') 
    133134        verbose_name_plural = _('Topics') 
     
    135136    def __unicode__(self): 
    136137        return self.name 
     138 
     139    def delete(self, *args, **kwargs): 
     140        last_post = self.posts.latest() 
     141        last_post.last_forum_post.clear() 
     142        forum = self.forum 
     143        super(Topic, self).delete(*args, **kwargs) 
     144        try: 
     145            forum.last_post = Topic.objects.filter(forum__id=forum.id).latest().last_post 
     146        except Topic.DoesNotExist: 
     147            forum.last_post = None 
     148        forum.topic_count = Topic.objects.filter(forum__id=forum.id).count() 
     149        forum.post_count = Post.objects.filter(topic__forum__id=forum.id).count() 
     150        forum.save() 
    137151 
    138152    @property 
Note: See TracChangeset for help on using the changeset viewer.