Hello everyone,
-- I'm new to Django and have a problem. I have a table in my database with records that contains data for different users. All I need to do is listing that data with a list_view for the user that is logged in. My code now looks like this:
class RoosterListView(LoginRequiredMixin, ListView):
queryset = Roosters.objects.filter(startvc__range=(DatumStart, DatumEind),username="My_name").order_by("startvc")[:35]
For the user 'My_name' this offcourse is okay. But when I login, it should be 'Ernst'. So:
uname = 'Ernst'
class RoosterListView(LoginRequiredMixin, ListView):
queryset = Roosters.objects.filter(startvc__range=(DatumStart, DatumEind),username=uname).order_by("startvc")[:35]
This also works fine. So what I want todo is fill the variable 'uname' with the username from the logged in user. How do I do that. I can't get it done.
For example I tried:
from django.contrib.auth.models import User
uname = User.username
no errors but also no data.
What am I doing wrong?
Thanks in advance.
Kind regards,
Ernst
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f8e28e62-2e4b-4513-aa97-d1aa5f7776e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment