Am trying to display only the appointments that the current logged in user has made, but i end up fetching all the appointments from the database

this the views.py file how can i display the appointments made the current logged in user

def user(request):
    client = Client.objects.all()
    appointments = Appointment.objects.all()

    context = {'appointments': appointments, 'client': client,
               }

    return render(request, 'users/user.html', context)

instead of using "all()" in your query use "filter()" "all()" gives you all the entries in the table. do something like this appointments = Appointment.objects.filter(user = request.user) the left side "user" inside the filter must be a column in the Appointment model/table. you can pass multiple parameters inside the filter.

Yea it worked. but i had to create a one to one relatioship between appointment and User

Back to Top