在one2many关系中添加当前记录的引用

2024-10-01 13:40:04 发布

您现在位置:Python中文网/ 问答频道 /正文

import openerp
from openerp import netsvc, tools, pooler
from openerp.osv import fields, osv
from openerp.tools.translate import _
import time
import sys
import os
import string
import logging

_logger = logging.getLogger(__name__)
#_logger.error("my variable : %r", my_var)



class reclamation(osv.Model):
    _name = '_reclamation'
    _columns = {
        'num': fields.char('Numéro'),
        'etat': fields.selection([('o','Ouvert'),('f','Fermé')],'Etat'),
        'catg': fields.selection([('p','Production'),('s','Sinistre')],'Catégorie'),
        'souscatg': fields.selection([('ppar','Production Particulier'),('ppro','Production Professionel'),('pent','Production Entreprise')],'Sous Catégorie'),
        'date' : fields.date('Date d\'ajout'),
        'sujet' : fields.text('Sujet'),
        'client': fields.many2one('res.partner','Client'),
    }
    _defaults = { 
        'num': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'reg_code'), 
    }

    def create(self, cr, uid, values, context=None):
        _logger.error("Beast Mod Is on")
        new_id = super(reclamation, self).create(cr, uid, values, context=context)
        index_instance = self.pool.get('_index')
        txt_fil = values['sujet']
        #List of the stopwords 
        stopwords = ("For","This")
        #List of the delimiters
        delimiter_chars = ",.;:!?"
        #Split the Text into words delimited by whitespace.
        words = txt_fil.split()
        #Remove unwanted delimiter characters adjoining words.
        words1 = [ word.strip(delimiter_chars) for word in words ]
        #Remove stopwords.
        """"words2 = words1[:]
        for word in words1:
            if word in stopwords:
                words2.remove(word)"""
        words2 = []
        [words2.append(word) for word in words1 if word not in stopwords]
        #Remove Duplicate
        ulist = []
        [ulist.append(word) for word in words2 if word not in ulist]
        #Supposedly after this we open Index Table and store the words, their occurences , and a reference for the records in which they were found 
        for word in ulist:
            vals_index = {}
            vals_index['mot'] = word
            vals_index['ref'] = new_id
            vals_index['prio'] = 0
            index_instance.create(cr,uid, vals_index , context=context)
        return new_id

reclamation()    


class index(osv.Model):
    _name = '_index'
    _columns = {
        'mot': fields.char('Mot Clé'),
        'ref' : fields.one2many('_reclamation','num','Reclamation'),
        'prio': fields.integer('Priorité'),
    }
    _defaults = {
        'prio' : 0,
    }       
index()

我正在创建一个索引类,它将索引索赔主题字段我的问题,我试图在创建声明后添加声明的记录id。在Postgres中,包含引用的更多信息都不存在于我的字段ref中


Tags: theinimportfieldsforuidindexcontext
1条回答
网友
1楼 · 发布于 2024-10-01 13:40:04
class parent(osv.Model):
    _name = 'parent'
    _columns = {
               'field1' : fields.one2many('child','field2','Childs Field'),
               }

class child(osv.Model):
    _name = 'child'
    _columns = {
               'field2': fields.many2one('parent', 'Parents Field'),
               }

子类中需要一个字段来保存父类的引用。从技术上讲,父id将存储在child中,而不是存储在parent中的child id。因为单亲家庭会有多个孩子。在数据库中,这是纯外键。对于你的案子

^{pr2}$

相关问题 更多 >