How to get the Id of the User logged in a Class Based View ?
Here is my CBW
class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'
context = 'activate'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['activate'] = 'Polls'
return context
def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.exclude(panel__user='???',
panel__valid=False)
.order_by('-pub_date')[:5]
With self.request.user
:
def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.exclude(panel__user=self.request.user,
panel__valid=False)
.order_by('-pub_date')[:5]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With