1👍
✅
You fetch the Post
s with:
posts = Post.objects.filter(status=True)
but it makes no sense to write:
posts.author
since posts
is a QuerySet
(so a collection) of Post
s, not a single one.
You can enumerate over the posts
and then show the .author
s for all Post
objects:
for post in posts:
print(post.author.about_user)
or in the template with:
{% for post in posts %}
{{ post.author.about_user }}
{% endfor %}
You can boost efficiency by fetching all the User
s in the same query with:
posts = Post.objects.filter(status=True).select_related('author')
Source:stackexchange.com