samedi 5 juin 2021

How to keep duplicate query set in django

Hello i am new to django and i am stuck in one small problem

def doctor_view_appointment(request):
    apptdoctor=models.Appointment.objects.all().filter(doctorId=request.user.id,status=True)
    pat_identity=[]
    for a in apptdoctor:
        pat_identity.append(a.patientId)
    print(pat_identity)
    pat_data=models.Patient.objects.all().filter(status=True,user_id__in=pat_identity)
    print(pat_data)
    appt_doctor=zip(apptdoctor,pat_data)
    data={
         'appt_doctor': appt_doctor,
    }
    return render(request,'doctor_view_appointment.html',context=data)

In this code the print result of pat_identity is [5, 20, 5] (they are appointmetn id) and the result of pat_data is <QuerySet [<Patient: User1>, <Patient: User2>]> but i need the result <QuerySet [<Patient: User1>, <Patient: User2>,<Patient: User1>]> what should i do for this output

Aucun commentaire:

Enregistrer un commentaire