Reputation: 5208
if a have a query like
following = Relations.objects.filter(initiated_by = request.user)
in which i'm having all the users followed by the currently logged in user, and i want to display those user's blog posts. Using a query like:
blog = New.objects.filter(created_by = following)
it only shows me the blog posts of the user with the id = 1 (though the currently logged in user doesn't actually follow him) in template i have :
{% for object in blog %}
<a href='/accounts/profile_view/{{object.created_by}}/'> {{object.created_by}}</a> <br />
{{object.post}}<br />
{% endfor %}
Where am i wrong?
Upvotes: 0
Views: 1454
Reputation: 968
Or even simpler :
bloc = New.objects.filter(created_by__initiated_by = request.user)
But that feels strange to me... are you sure of your model design ?
Upvotes: 0
Reputation: 5893
.filter()
returns a collection, not an occurence. Thus, I'd say problem is that second query should be
blog = New.objects.filter(created_by__in = following)
Upvotes: 2