[Answered ]-Django: Show data from current user

1👍

Simply you can try like this:

         if queryset:
            for obj in queryset:
                id = Rostering.objects.get(rosteringuser=obj.id)
                obj.id = id
                querysets = obj
            return render(request, 'my_shift.html', {'querysets': querysets})

And in templates:

{% for object in querysets %}
<tr>
    <td>{{ object.user.user_name }}</td>
    <td>{{ object.id.name }}-{{ object.id.begin_time }}</td>
    <td>{{ object.id.name }}-{{ object.id.end_time }}</td>
</tr>
{% endfor %}

0👍

def my_shift(request):
    if request.method == 'GET':
        rost_id = RosteringUser.objects.filter(user_id=request.user.id).values("rostering_user_id").first()
        if rost_id :
           data = Rostering.objects.get(id=rost_id['rostering_user_id'])
           return render(request, 'my_shift.html', {'queryset': data })

in template you can directly display logged in username {{ request.user.first_name }}

Leave a comment