我希望在Odoo 10中的数据库上插入记录之前加上一个字段。
我试过这个并运作良好:
df
# X Case1 Case2 Case3 Gene_Symbol
#8026 8025 0.532672 0.000000 0.000000 GAPDHS;TMEM147
#32531 32530 0.000000 0.541698 0.000000 GAPDHS;TMEM147
#57051 57050 0.000000 0.000000 0.482159 GAPDHS;TMEM147
df.drop('X', 1, inplace=True)
df.set_index('Gene_Symbol').stack()[lambda x: x != 0].unstack(level=1).reset_index()
# Gene_Symbol Case1 Case2 Case3
#0 GAPDHS;TMEM147 0.532672 0.541698 0.482159
但是如果我添加像
这样的其他内容#include <stdio.h>
typedef struct {
int a:1;
int b:1;
int c:1;
int d:1;
} bitField;
int main() {
bitField A;
bitField B;
int *allA;
allA = (int *)&A; //Access bitField as Integer
*allA = 0x02; //Set bit 2 of A
printf("A=0x%x\n", A);
*allA = 0x53; //Set bits 1 and 2 of A, but also set a few of "out of range" bits
printf("A=0x%x\n", A);
*allA = 0x01; //Set bit 1, reset all other bits
printf("A=0x%x\n", A);
B.c = 1; //Set Bit 3 of B
A.c |= B.c; //A=0b0001, B=0b0100 -> A|B=0b0101 (dec 5)
printf("A=0x%x\n", A);
int *allB;
allB = (int *)&B;
*allA = 0;
*allB = 3;
*allA |= *allB; //Set bits 1 and 2 of A by OR-ing with B;
printf("A=0x%x\n", A);
}
总是返回else的ValidationError(当if语句为true时,因为没有其他工作正常)
任何人都可以帮助我吗?感谢。
答案 0 :(得分:0)
每次尝试设置&#34; field&#34;的值它会触发约束 本身,这将导致&#34; RECURSION&#34; !!
这里因为递归而总是因为引发ValidationError(&#34;错误&#34;)而结束。
==&gt;这里当您转换&#34; field&#34;的值时,首先发生的事情是什么?来自&#39; x&#39;到&#39; X&#39;并再次将其设置为字段执行此调用再次使用值&#39; X&#39;并且您的条件变为False并引发错误。
将print语句放入if&amp;否则检查控制台你会得到更好的想法!
答案 1 :(得分:0)
检查这是否有助于你
@api.constrains('name')
def _check_name(self):
if self.name:
final_name=''
for letters in self.name:
if re.match(r'[a-zA-Z0-9\- .]',letters):
final_name += letters
else:
not_accept_letters = letters
raise ValidationError(_('The character that you entered has not accepted %s')% not_accept_letters)
if self.name.islower():
self.name = final_name.upper()