1👍
You can override get_queryset()
:
class ProfileView(ListView):
template_name = 'posts/profile.html'
model = Post
def get_queryset(self, **kwargs):
return super().get_queryset(**kwargs).filter(
author__username=self.kwargs['username']
)
Note: In Django, class-based views (CBV) often have a
…View
suffix, to avoid a clash with the model names.
Therefore you might consider renaming the view class toProfileView
, instead of.Profile
Source:stackexchange.com