Ignore:
Timestamp:
Mar 4, 2012 3:35:02 PM (16 months ago)
Author:
Igor Yanchenko <yanchenko.igor@…>
Branch:
default
Message:

moved reply_count_minus and reply_count_plus to manager and use_for_related_fields set True

File:
1 edited

Legend:

Unmodified
Added
Removed
  • djangobb_forum/models.py

    r401 r402  
    316316 
    317317class ProfileManager(models.Manager): 
     318    use_for_related_fields = True 
    318319    def get_query_set(self): 
    319320        qs = super(ProfileManager, self).get_query_set() 
    320321        if forum_settings.REPUTATION_SUPPORT: 
    321             qs = qs.extra(select={'reply_total':'Select sum(sign) from djangobb_forum_reputation where to_user_id = djangobb_forum_profile.user_id group by to_user_id'}) 
     322            qs = qs.extra(select={ 
     323                'reply_total':'Select sum(sign) from djangobb_forum_reputation where to_user_id = djangobb_forum_profile.user_id group by to_user_id', 
     324                'reply_count_minus':"Select sum(sign) from djangobb_forum_reputation where to_user_id = djangobb_forum_profile.user_id and sign = '-1' group by to_user_id", 
     325                'reply_count_plus':"Select sum(sign) from djangobb_forum_reputation where to_user_id = djangobb_forum_profile.user_id and sign = '1' group by to_user_id", 
     326                }) 
    322327        return qs 
    323328 
     
    364369            return  None 
    365370 
    366     def reply_count_minus(self): 
    367         return Reputation.objects.filter(to_user__id=self.user_id, sign=-1).count() 
    368  
    369     def reply_count_plus(self): 
    370         return Reputation.objects.filter(to_user__id=self.user_id, sign=1).count() 
    371  
    372  
    373371class PostTracking(models.Model): 
    374372    """ 
Note: See TracChangeset for help on using the changeset viewer.