看了Tryton的代码模块,这个方法我遇到了很多,但一直没弄清楚这是干什么用的。
这个函数在Tryton中有什么用?
@classmetod
def __register__(cls,module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = TableHandler(cursor,cls,module_name)
super(Adress,cls).__register__(module_name)
table.not_null_action('sequence', action='remove')
最佳答案
每次更新模型时都会调用__register__ 方法,它用于改变当前模块的数据库结构。通常 tryton,为您创建所有缺失的字段(这是在 ModelSQL 类上完成的),但有些操作无法自动检测到,因此您必须为其编写迁移。这是在模型的 __register__ 方法上完成的。
您复制的代码确保序列字段可以为 null,如果不能,它会将列从 null 更改为 not null。
关于python - tryton中这个函数有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25422349/