12👍
✅
You can’t filter on the user in your urls.py
, because you don’t know the user when the urls are loaded.
Instead, subclass ListView
and override the get_queryset
method to filter on the logged in user.
class PendingApplicationView(ListView):
def get_queryset(self):
return Application.objects.filter(status='IP', principle_investigator=self.request.user)
# url pattern
url(r'^application/pending/$', PendingApplicationView.as_view()),
Source:stackexchange.com