odoo self.ensure_one()
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                odoo self.ensure_one()
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                源碼:
def ensure_one(self):""" Verifies that the current recorset holds a single record. Raises
an exception otherwise.
"""
try:
# unpack to ensure there is only one value is faster than len when true and
# has a significant impact as this check is largely called
_id, = self._ids # 開始沒明白什么意思,應該是python的多重賦值,只不過這種寫法的情況下等號右邊必須是可迭代的
return self
except ValueError:
raise ValueError("Expected singleton: %s" % self)
?
?
這段代碼如果換種方式就很好理解了:
def ensure_one(self):"""換種寫法"""if len(self) == 1:
return self
else:raise ValueError("Expected singleton: %s" % self)
?
?
?
?
轉載于:https://www.cnblogs.com/yanhuaqiang/p/11616834.html
總結
以上是生活随笔為你收集整理的odoo self.ensure_one()的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 再生资源回收经营备案证怎么办理?
- 下一篇: UNIXsystemv是什么?
