El 03/05/17 a les 04:23, Carlos Ibrahim Arias ha escrit:
Hi! I'm having problems using a one2many field on another model
different from the class it was created on. I tried to use a many2many
field so that I can view the related fields but cant make it work

I'm not sure to understand what are you trying to achieve. Can you elaborate?


This is the first class...

|
classZ_MedicalHistory(ModelSQL,ModelView):

    'Patient Medical History'
    __name__ ='gnuhealth.z_medical_history'

    medical_history_date =fields.DateTime('Date and Time',required=True)

    healthprof =fields.Many2One(
        'gnuhealth.healthprofessional','Health Prof',
        select=True,required=True,help='Health Professional')

    patient =fields.Many2One(
        'gnuhealth.patient','Patient',
        select=True,required=True,help='Patient Name')

    comments =fields.Text('Comments',required=True)

    @staticmethod
    defdefault_medical_history_date():
        returndatetime.now()

    @staticmethod
    defdefault_healthprof():
        pool =Pool()
        HealthProfessional=pool.get('gnuhealth.healthprofessional')
        returnHealthProfessional.get_health_professional()


    @staticmethod
    defdefault_patient():
        pool =Pool()
        Patient=pool.get('gnuhealth.patient')
        returnPatient.name
|


I added the following lines to the class PatientData (gnuhealth.patient)
so that they are related

|
    z_medical_history =fields.One2Many(
        'gnuhealth.z_medical_history',
        'Z_MedicalHistory','Patient Medical History',help='Enter the
Patient Medical History'
        ' for the patient.')


The second argument of the One2Many field is the target field. This means the name of the field which has the reverse Many2One relation in the target model. So in your case you have yo change 'Z_MedicalHistory' for 'patient'.
|


The problem is that there is another class call PatientEvaluation where
I need to hace access and view Z_MedicalHistory using the patient field
of PatientEvaluation.

With this description, I imagine you want a function field that returns all the MedialHistory entries for this patient, not a Many2Many.

Tried the following but it's not working:

|
    z_medical_history =fields.Many2Many('gnuhealth.z_medical_history',
        'patient',None,'Historial Medico del Paciente',
        domain=[('patient','=',Eval('patient'))],
        depends=['patient'])
|

Many2Many fields require an intermediary table to store the relation between both records.

I guess I'm not doing it right. :(

Thanks it advanced!

Hope it helps.


--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

--
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/e2e4884b-8c6a-3103-1d7e-389b7a08ecdc%40koolpi.com.

Reply via email to