在我看来,这样做是为了作为形式的一部分更新某些植被。
i e seen tons of stuff on how to do it, i ve followed it and got nearly there. i ve got a bit of code below which is called to populate the select with the choices and it does, but i think the formatting is out, as its passing back a unicode string and i think it needs to be a tuple.
assigning the choices
form.fields[ size_option ].widget.attrs[ choices ] = Product.get_options(product)
产生选择的法典
def get_options(self):
optionset = "("
for option in self.optionset.options.all():
optionset = optionset + "( " + option.name + " , " + option.name + " )"
optionset = optionset + ")"
pdb.set_trace()
return optionset
选择的html如下。
<select id="id_size_option" name="size_option" choices="(('Small', 'Small')('Medium', 'Medium')('Large', 'Large'))">
因此,问题可能是背后的各种选择。 i 可以想象。 i 根本不知道什么错误。 i 无法找到文件,说明如何在选择中加以编排。