我必须在Odoo 8中将Purchase Order Line设置为可编辑.目前,Purchase.Order Model中的字段order_line具有以下修饰符:
'order_line': fields.one2many('purchase.order.line', 'order_id', 'Order Lines',
states={'approved':[('readonly',True)],
'done':[('readonly',True)]},
copy=True)
Run Code Online (Sandbox Code Playgroud)
因此,如果批准或完成,州是只读的.我想删除它.我试过以下:
<field name="order_line" position="attributes">
<attribute name="readonly">0</attribute>
</field>
Run Code Online (Sandbox Code Playgroud)
也,
<xpath expr="//field[@name='order_line']" position="attributes">
<attribute name="readonly">0</attribute>
</xpath>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
请帮忙
谢谢,
class PurchaseOrder(models.Model):
'''
classdocs
'''
_name = 'purchase.order'
_inherit = 'purchase.order'
total_cases = fields.Integer('Total Cases', default=None)
appointment_number = fields.Char('Appointment Number', default=None)
order_line = fields.One2many('purchase.order.line', 'order_id', 'Order Lines', copy=True)
Run Code Online (Sandbox Code Playgroud)
我如上所述覆盖了字段order_line,但没有任何反应
为什么在vanilla JS和jQuery中更改元素的属性值有时不会起作用?一种情况是我创建的实验,无论何时单击"显示密码"按钮,密码字段的type属性值都应该更改为何text时password,反之亦然.它在vanilla JS中成功运行,但在jQuery中却没有.在jQuery中,属性值会更改为text,但是当我想将其更改回时password,它将无法工作.为什么会出现这样的问题?
香草JS
document.querySelector('.show-password').onclick = function() {
if(document.querySelector('#password').type == 'password') {
document.querySelector('#password').type = 'text';
} else {
document.querySelector('#password').type = 'password';
}
}
Run Code Online (Sandbox Code Playgroud)
jQuery的
$('.show-password').click(function() {
if($('#password').attr('type', 'password')) {
$('#password').attr('type', 'text');
} else {
$('#password').attr('type', 'password');
}
});
Run Code Online (Sandbox Code Playgroud) 我试图从继承自类的对象中打印所有值,这是我的示例:
我创建类:
class Pokemon {
var name: String?
var type: String?
var level: Int?
var exp = 0.0
}
Run Code Online (Sandbox Code Playgroud)
创建对象并分配一些值:
var pikachu = Pokemon()
pikachu.name = "Pika Pika"
pikachu.level = 1
pikachu.type = "electricity"
pikachu.exp = 0
Run Code Online (Sandbox Code Playgroud)
现在,我想遍历所有皮卡丘对象属性并打印值。我在为每个循环考虑,但我不确定如何实现它。
我知道我可以做这样的事情:
func printStats(pokemon: Pokemon) {
if pokemon.name != nil {
print(" name: \(pokemon.name!)\n level:\(pokemon.level!)\n type:\(pokemon.type!)\n exp: \(pokemon.exp!)")
}
}
printStats(pokemon: pikachu)
Run Code Online (Sandbox Code Playgroud)
输出:
name: Pika Pika
level:1
type:electricity
exp: 0.0
Run Code Online (Sandbox Code Playgroud)
但是我只想遍历所有值,而不是显式地编写函数中的每个属性。
在类中的方法中引用具有新变量名的属性是不好的做法吗?例如:
class Stuff:
def __init__(self, a):
self.a = a
def some_method(self):
a = self.a
# Do some stuff with a
Run Code Online (Sandbox Code Playgroud)
我已经在其他人的代码中看到了这一点,我已经养成了自己的习惯,尤其是长变量名.a当我这样做时,它似乎是一个副本,如果a非常大,可能会出现问题.我是不是应该坚持呼吁self.a里面some_method?python垃圾会a在some_method调用后收集创建的吗?
我对下面的Python行为感到困惑.为什么第二个和第三个实例(b,c) i的属性是类属性i但a行为不同?
In [47]: class Foo:
...: i=0
...:
In [48]: a = Foo()
In [49]: a.i = 1
In [50]: a.i
Out[50]: 1
In [51]: Foo.i
Out[51]: 0
In [52]: b = Foo()
In [53]: b.i
Out[53]: 0
In [54]: Foo.i is b.i
Out[54]: True
In [55]: Foo.i is a.i
Out[55]: False
In [56]: c = Foo()
In [57]: Foo.i is c.i
Out[57]: True
Run Code Online (Sandbox Code Playgroud) 我不知道用什么语法谷歌这个.
考虑这个属性:
[MyAttribute(MyOption=true,OtherOption=false)]
Run Code Online (Sandbox Code Playgroud)
那是什么Name=value部分?我如何在自己的自定义属性中实现它?
我有一个名为settings的python类,其中包含一个__init__设置如下值的方法:
class settings:
global appkey
global appversion
def __init__(self):
appkey = 1
appversion = 1
applicationname = "app1"
applicationfile = "app.txt"
Run Code Online (Sandbox Code Playgroud)
在另一个python文件(主脚本)中,我通过以下代码定义了我的设置类的实例:
import settings
from settings import settings
set = settings()
print set.appversion
print set.appkey
print set.applicationfile
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的主要python脚本时,我收到了这个错误:
AttributeError: settings instance has no attribute 'appversion'
Run Code Online (Sandbox Code Playgroud)
我希望当我在这里定义一个类的实例,设置类时,它的init函数将被触发,我将拥有其属性的值.
我正在尝试创建一个应用程序,而它通过一个网页运行并找到一个href属性,但是现在我想找到href属性,并提醒我链接.
我是JQuery的新手,但我试图通过Fiddle运行以下内容,但我似乎无法让它运行:
$('soundTitle__tag sc-tag sc-tag-small').on("click", function() {
var self = $(this);
var link = self.find("a").attr('href');
alert(link);
})Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="link-redirect">
<div class="soundTitle__tagContainer">
<a class="soundTitle__tag sc-tag sc-tag-small" href="/home">1</a>
</div>
<div class="soundTitle__tagContainer">
<a class="soundTitle__tag sc-tag sc-tag-small" href="/home">2</a>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
我有一个Django ModelForm,可以在form __init__()方法中设置某些表单属性。
class MyForm(forms.ModelForm):
class Meta:
model = MyModel
exclude = ['datecreated', 'datemodified']
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields['field1'].widget.attrs['class'] = 'class1'
self.fields['field2'].widget.attrs['class'] = 'class1'
self.fields['field3'].widget.attrs['class'] = 'class1'
# override Google Chrome field error issues making form unfocusable
self.fields['field1'].required = False
self.fields['field2'].required = False
self.fields['field3'].required = False
Run Code Online (Sandbox Code Playgroud)
是否可以设置表格中包含的所有字段的属性,而无需为每个字段分别编写self.fields?
我正在改写这个scale功能.我想获得数据集树的相同结果.但是当我运行代码时,我得到一个非常奇怪的结果.
z_function = function(x){
(x - mean(x))/sd(x)}
scale_function = function(x){
result = apply(x,2,z_function)
att_mean = apply(x,2,mean)
att_sd = apply(x,2,sd)
attributes(result) = list("scaled:center" = att_mean,"scaled:scale"= att_sd)
result
}
scale_function(trees)
Run Code Online (Sandbox Code Playgroud)
预期结果:
# Girth Height Volume
# [1,] -1.57685421 -0.9416472 -1.20885469
# [2,] -1.48125614 -1.7263533 -1.20885469
# [3,] -1.41752409 -2.0402357 -1.21493821
# [4,] -0.87580169 -0.6277648 -0.83775985
# [5,] -0.81206964 0.7847060 -0.69175532
# [6,] -0.78020362 1.0985884 -0.63700362
# [7,] -0.71647157 -1.5694121 -0.88642802
# [8,] -0.71647157 -0.1569412 -0.72825645
# [9,] -0.68460554 0.6277648 -0.46058149 …Run Code Online (Sandbox Code Playgroud) attributes ×10
class ×4
python ×4
javascript ×2
jquery ×2
c# ×1
django ×1
foreach ×1
forms ×1
html ×1
html5 ×1
init ×1
input ×1
odoo-8 ×1
openerp ×1
python-2.7 ×1
python-3.x ×1
r ×1
swift3 ×1