Help with Query in django

0

I have the following query:

 comision = comisiones_pagadas.objects.values('codigo_proceso','fecha_pago','doctor_id').order_by('-fecha_pago').distinct()

At the moment of passing 'commission' to the template I can not present the doctor's name: that is. comision.doctor.nombres since doctor_id is foreign key of the table Doctors, apparently the query does not get it as an object but as a dictionary of values, how could you solve it?

    
asked by Roberto Feijoo 23.10.2018 в 17:32
source

2 answers

0

The method is being used in the query .values that only leaves the fields that you list as parameter 'codigo_proceso','fecha_pago','doctor_id' , that's where you have to add the field doctor__nombre (note that it is a double underscore because you are selecting the field name of object Doctor.nombre related.

Your query should look like this:

comision = comisiones_pagadas.objects.values('codigo_proceso','fecha_pago','doctor_id', 'doctor_name').order_by('-fecha_pago').distinct()
    
answered by 24.10.2018 / 20:11
source
0

Hello, when you do the query you only have the id of the doctor, I do not know what type of relationship you have commissions with a doctor if it is OneToOne you can try to access the value of the doctor's name doctor__nombre , if it's ManyToMany you can save it in a separate variable doing doctores = comision.doctor.all()

    
answered by 24.10.2018 в 03:35