justquick / django-activity-stream

Generate generic activity streams from the actions on your site. Users can follow any actors' activities for personalized streams.
http://django-activity-stream.rtfd.io/en/latest/
BSD 3-Clause "New" or "Revised" License
2.38k stars 482 forks source link

Filter user feed with distinct('action_object') #518

Open Quasarman opened 2 years ago

Quasarman commented 2 years ago

Hello,

first of all everything is working like a charm! I was just wondering if and how i can only display action objects that are distinct. I dont want to i.e., show duplicate comments if they have for example a different actor and target but the user is following both. I added a GenericRelation on the action object I want to filter distinct but I get a cast error. I will provide more info once I debugged further, just wanted to ask if this is even possible so I dont waste no more time on this issue.

Br, Johannes

justquick commented 1 year ago

Thanks Johannes! Yes there is a way for you to make an easily accessible stream that is based off a query that can do queryset.distinct() and fetch the results in a view/template. You just need to define your own ActionManager if you have not done so and implement your shortcuts using the @stream decorator. Please see this section on creating custom streams

https://django-activity-stream.readthedocs.io/en/latest/streams.html#writing-custom-streams

You would probably want to do something along the lines of obj.actor_actions.values('comment').distinct() or something like that. Let me know if you get stuck

What is the cast error that you are seeing? Are the primary keys of the models you are filtering of different type?