Closed rollue closed 3 years ago
this is how I did it - by using Subquery
from django.db.models import OuterRef, Subquery
...
def get(self, request, *args, **kwargs):
qs = ActionProxy.objects.user(request.user, with_user_activity=False)
qs = qs.exclude(verb="started following")
qs = qs.exclude(actor_object_id=request.user.id)
follow = Follow.objects.filter(
content_type_id=OuterRef("target_content_type_id"),
object_id=OuterRef("target_object_id"),
user=request.user,
)
qs = qs.annotate(followed_at=Subquery(follow.values("started")[:1])).filter(
timestamp__gte=F("followed_at")
)
ser = FeedSerializer(qs, many=True, context={"request": request})
return response.Response(ser.data)
is it needed in the package?
I resorted to django-notifications instead of django-activity-stream.
I was implementing a notifications API for my app. The problem with django-activity-stream was that once a user has unfollowed an object, all notifications regarding that objects disappeared from the API, regardless of WHEN the user unfollowed that object.
I needed to make sure some of the notifications(or actions
) - which were created between the timeframe when the user started following and decided to unfollow - were still visible to the user. This was very hard to implement with django-activity-stream.
Currently user_stream seems to return all actions related to specific user/object. What I need is to filter out to get only actions that happened after someone has started following the user/object. For example, if a user started following a post to get notifications on new comments, I don't need to notify the user for actions related to already existing comments. This can probably be done with individual model streams, but is there a way to implement this with user_stream?
Thanks.