Is there any way that using get_context_data from ListView, first check if the user is logged in and if not, then make a redirect, and if so, already give context? I understand why this code doesn't work, because only the context is expected, and in case of a redirect I get an error, but how can I make it work?
class TasksListView(ListView):
template_name = "pages/tasks.html"
model = Tasks
def get_context_data(self, **kwargs):
**if self.request.user.is_authenticated:**
context = super().get_context_data(**kwargs)
if self.request.GET.get('self_tasks'):
queryset = self.get_queryset().filter(creator_id=self.request.user.pk)
else:
queryset = self.get_queryset()
context['filter'] = TasksFilter(self.request.GET, queryset=queryset)
return context
**else:
redirect('login')**