(self,data)
return mm
创建一个新的对象
创建一个新的对象
创建一个新的对象
def new(self,data):
        """创建一个新的对象
        """
        incrkey = self.incrkey
        tablename = self._name
        if incrkey:
            result = util.InsertIntoDBAndReturnID(tablename, data)
            data[incrkey] = result[0]
            pk = data.get(self.pk)
            if pk is None:
                raise PKValueError(data)
            mm = MMode(self._name+':%s'%pk,self.pk,data=data,fk=self._fk,timeout=self.timeout)
        else:
            pk = data.get(self.pk)
            result = util.InsertIntoDB(tablename, data)
            if not result:
                raise util.SQLError()
            mm = MMode(self._name+':%s'%pk,self.pk,data=data,fk=self._fk,timeout=self.timeout)
        mm.insert()
        if self._fk:
            fk = data.get(self._fk,0)
            name = '%s_fk:%s'%(self._name,fk)
            fkmm = MFKMode(name)
            pklist = fkmm.get('pklist')
            pklist = self.getAllPkByFk(fk)
            pklist.append(pk)
            fkmm.update('pklist', pklist)
        return mm
def new ( self , data ) : incrkey = self . incrkey tablename = self . _name if incrkey : result = util . InsertIntoDBAndReturnID ( tablename , data ) data [ incrkey ] = result [ 0 ] pk = data . get ( self . pk ) if pk is None : raise PKValueError ( data ) mm = MMode ( self . _name + ':%s' % pk , self . pk , data = data , fk = self . _fk , timeout = self . timeout ) else : pk = data . get ( self . pk ) result = util . InsertIntoDB ( tablename , data ) if not result : raise util . SQLError ( ) mm = MMode ( self . _name + ':%s' % pk , self . pk , data = data , fk = self . _fk , timeout = self . timeout ) mm . insert ( ) if self . _fk : fk = data . get ( self . _fk , 0 ) name = '%s_fk:%s' % ( self . _name , fk ) fkmm = MFKMode ( name ) pklist = fkmm . get ( 'pklist' ) pklist = self . getAllPkByFk ( fk ) pklist . append ( pk ) fkmm . update ( 'pklist' , pklist ) return mm