具有多选字段的 PloneFormGen
我正在 Plone/PloneFormGen 中创建表单。该表单具有多选字段,我从 MySQL 数据库填充该字段作为键,值
1, Option 1
2, Option 2
3, Option 3
etc...
它作为键数组存储到 MySQL 表中 ['2', '4']
现在我想创建一个编辑表单来编辑旧数据。 如何在编辑表单中选择旧的选定选项(存储在数据库中)作为默认选项?我一直在尝试使用不同的选项进行覆盖,但似乎没有任何效果。我有一个 pythos 脚本来提取数据,但是......
版本 克隆人3.3.5 PloneFormGen 1.6.3
I'm in process creating a form in Plone/PloneFormGen. This form has Multi-Select field that I am populating from MySQL database as key,value
1, Option 1
2, Option 2
3, Option 3
etc...
This is stored into MySQL table as an array of keys ['2', '4']
Now I want to create an editing form to edit old data.
How I can get old selected options (stored in database) to be selected as a default in edit form? I have been attemting overrides with diffrent options, but nothing seems to work. I have a pythos script to extract the data, but...
Version of
Plone 3.3.5
PloneFormGen 1.6.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题不仅仅是格式化。字符串还必须转换为整数。
我用下面的代码解决了它。
这是 python 脚本的一部分,我在其中从 SQL 提取数据以填充 PloneFormGen 中的表单。
这会将逗号分隔的字符串转换为包含整数的元组...
The Problem was not only formatting. Also string had to be converted to integers.
I solved it with a following code.
This is part of a python script, where I pull data from SQL to populate the form in PloneFormGen.
This will convert comma separated string to a tuple containing integers...
很可能您返回的数据实际上并不是列表形式。它可能只是一个格式化的字符串。因此,您需要使用脚本将字符串转换为值列表。
如果您可能的值是简单字符,这可能非常简单:删除括号、空格和引号,然后用逗号分隔。
Odds are that your returned data isn't actually in list form. It's probably just a formatted string. So, you'll need to use your script to convert the string to a list of values.
If your possible values are simple characters, this may be very simple: remove the brackets, spaces and quotes, then split on commas.