0👍
✅
you can get the username of your logged in user by
username = request.user
you can simply pass your request parameter around to get all the information of the current session and do whatever query you wanna do.
1👍
Remove the username = User.username
line – User
is the model class, not the current user instance.
You can access the current user if you set queryset
, as this is loaded when the module is imported, not when the request is made. If you override the get_queryset
method, you can access the user with self.request.user
.
class RoosterListView(LoginRequiredMixin, ListView):
def get_queryset(self):
return Roosters.objects.filter(startvc__range=(DatumStart, DatumEind), username=self.request.user.username).order_by("startvc")[:35]
- Why does dict.key returns value in Template but not in Views
- Why does my Django form show choice not available error?
- Data always resets to original state on heroku free account after some time
- How to create nested form in django?
Source:stackexchange.com