Commits

Denis Golomazov  committed 0dc2307

Add actors_stream function for fetching activity by a set of actors

  • Participants
  • Parent commits 397bb7d

Comments (0)

Files changed (1)

File actstream/models.py

             actor_object_id = actor.pk,
         ).order_by('-timestamp')
 
+    def stream_for_actors(self, actors_class, actors_ids):
+        """
+        Produces a QuerySet of most recent activities for any list of actors ids of given actors_class
+        """
+        return self.filter(
+            actor_content_type = ContentType.objects.get_for_model(actors_class),
+            actor_object_id__in = actors_ids,
+        ).order_by('-timestamp')
+
     def stream_for_model(self, model):
         """
         Produces a QuerySet of most recent activities for any model
     return Action.objects.stream_for_actor(actor)
 actor_stream.__doc__ = Action.objects.stream_for_actor.__doc__
 
+def actors_stream(actors_class, actors_ids):
+    return Action.objects.stream_for_actors(actors_class, actors_ids)
+actors_stream.__doc__ = Action.objects.stream_for_actors.__doc__
+
 def user_stream(user):
     return Follow.objects.stream_for_user(user)
 user_stream.__doc__ = Follow.objects.stream_for_user.__doc__