Displaying the activity stream

Finally, we will need a way to display the activity stream for each user. We will include the activity stream in the user's dashboard. Edit the views.py file of the account application. Import the Action model and modify the dashboard view, as follows:

from actions.models import Action@login_requireddef dashboard(request):    # Display all actions by default    actions = Action.objects.exclude(user=request.user)    following_ids = request.user.following.values_list('id',                                                       flat=True)    if following_ids:        # If user is following others, retrieve only their actions        actions = actions.filter(user_id__in=following_ids)    actions = actions[:10]    return render(request,                  'account/dashboard.html',                  {'section': 'dashboard',                   'actions': actions ...

Get Django 2 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.