@@ -9,18 +9,24 @@ def fast(self):
9
9
return self .select_related ('user' ).all ()
10
10
11
11
def aggregate_counts (self , content_type , object_id , active = True ):
12
- return self .fast ().filter (
13
- Q (content_type = content_type ) &
14
- Q (object_id = object_id ) &
15
- Q (active = True )
16
- ).values ('activity_type' ).annotate (total = Count ('activity_type' ))
12
+ counts_filter = Q (content_type = content_type )
13
+ counts_filter &= Q (object_id = object_id )
14
+ counts_filter &= Q (active = True )
15
+
16
+ return self .fast ()\
17
+ .filter (counts_filter ) \
18
+ .values ('activity_type' ) \
19
+ .annotate (total = Count ('activity_type' ))
17
20
18
21
def user_actions (self , user , content_type , object_id ):
19
- return self .fast ().filter (
20
- Q (user__id = user .id ) &
21
- Q (content_type = content_type ) &
22
- Q (object_id = object_id )
23
- ).values ('id' , 'active' , 'activity_type' ).distinct ()
22
+ actions_filter = Q (user__id = user .id )
23
+ actions_filter &= Q (content_type = content_type )
24
+ actions_filter &= Q (object_id = object_id )
25
+
26
+ return self .fast () \
27
+ .filter (actions_filter ) \
28
+ .values ('id' , 'active' , 'activity_type' ) \
29
+ .distinct ()
24
30
25
31
26
32
class CommentQuerySet (models .QuerySet ):
0 commit comments