تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
6142 أدوات العرض

Hi,

My table is,

class ClientRequestPathology(models.Model):

 _name = "client.request.pathology.info"

 _description = "Client Request Pathology Info"  


 ### Test Details

  cytology_ids = fields.Many2many('cytology.info', 

                                    'pathology_cytology_rel', 

                                    'pathology_c_id', 

                                    'cytology_id', string="Cytology_datas", copy=False)


Relation table is,

class CytologyInfo(models.Model):

     _name="cytology.info"

    _description="Cytology Info"   

    _rec_name = "description"

    

    description = fields.Char('Description',required="True") # Enter The Description

    price = fields.Float("Price")

    pathology_c_ids = fields.Many2many('client.request.pathology.info', 

                                     'pathology_cytology_rel',

                                     'cytology_id',

                                     'pathology_c_id', string="Pathology datas") # Many2many Relation


In controller,

pathology_id = 2

cr_pathology_module      = pool['client.request.pathology.info']

cr_pathology_id = cr_pathology_module.search([('id', '=', pathology_id)])

 

print "View----------------->"cr_pathology_id.cytology_ids.description


OUTPUT:

ValueError: Expected singleton: cytology.info(1, 4)


how to get value for cytology.info(1, 4) table  field(e.g: description field)


Thanks in advance...

please help me...

الصورة الرمزية
إهمال
أفضل إجابة

Hai MaruthaMuthu,

There  is more than one record that is why getting the singleton error.
So before printing  use a for loop like this.

Thank you

for rec in cr_pathology_id.cytology_ids:
     print "description is ", rec.description
الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Thank you, Mr.Niyas Raphy

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
مايو 17
10808
0
يوليو 22
1249
1
يناير 22
10921
4
فبراير 20
3790
1
يوليو 19
6144