web2py 自动填充/自动完成返回 id

发布于 2024-12-09 07:01:34 字数 1291 浏览 0 评论 0原文

我有一个 from,我想根据数据库和填充字段中的信息自动填充它:

在 db_wizard.py 中,

db.define_table('receiver',
  Field('name'), # e.g. Daniel
  Field('email'),# e.g. [email protected]
  Field('opening'), # e.g. Dear Daniel
  ...)           

db.define_table('sender',
  Field('name'),  # e.g. John
  Field('email'), # e.g. [email protected]
  Field('tel'),   # e.g. 111 222 111
  ...)

db.define_table('letter',
  Field('sender', db.sender.id),     # e.g. Daniel
  Field('receiver', db.receiver.id), # e.g. John
  Field('opening'), # should be filled automatically when choosing/changing the value of "receiver"
  ...)

我使用plugin_lazy_widget

db.letter.opening.widget = suggest_widget(db.receiver.opening, id_field=db.i2l_receiver_profile.id, 
                                          limitby=(0,10), min_length=1, db=db(db.i2l_receiver_profile.user_id==auth.user_id))

,但此小部件甚至 web2py_autocomplete_widget 始终返回的 ID选择记录!而不是我们真正放入“opening”中的内容,如上面的示例:它返回 1 而不是 Dear Daniel

i've a from and i want to fill it automatically based on information from a database and filled fields :

in db_wizard.py

db.define_table('receiver',
  Field('name'), # e.g. Daniel
  Field('email'),# e.g. [email protected]
  Field('opening'), # e.g. Dear Daniel
  ...)           

db.define_table('sender',
  Field('name'),  # e.g. John
  Field('email'), # e.g. [email protected]
  Field('tel'),   # e.g. 111 222 111
  ...)

db.define_table('letter',
  Field('sender', db.sender.id),     # e.g. Daniel
  Field('receiver', db.receiver.id), # e.g. John
  Field('opening'), # should be filled automatically when choosing/changing the value of "receiver"
  ...)

i use the plugin_lazy_widget

db.letter.opening.widget = suggest_widget(db.receiver.opening, id_field=db.i2l_receiver_profile.id, 
                                          limitby=(0,10), min_length=1, db=db(db.i2l_receiver_profile.user_id==auth.user_id))

but this widget or even the web2py_autocomplete_widget returns always the ID of the chosen record! and not what we really put in "opening", like the example above: it returns 1 and not Dear Daniel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江南月 2024-12-16 07:01:34

我认为您不想使用 suggest_widget (或内置的自动完成小部件)。相反,您希望在用户选择接收者后立即动态填充“开放”字段。为此,您可能需要 lazy_options_widget 的修改版本(不与 suggest_widget 一起使用) 。

另请注意,使用带有“opening”字段的 id_field 无论如何都是不合适的,因为它不是引用字段(因此没有关联的 id 可供引用)。

I don't think you want to use the suggest_widget (or the built-in autocomplete widget). Instead, you want the 'opening' field dynamically filled in as soon as the user selects a receiver. For that, you probably need a modified version of the lazy_options_widget (not used in conjunction with the suggest_widget).

Also, note that using an id_field with the 'opening' field wouldn't be appropriate anyway because it is not a reference field (so there is no associated id to reference).

谁的新欢旧爱 2024-12-16 07:01:34

相反:

db.letter.opening.widget = suggest_widget(db.receiver.opening, id_field=db.i2l_receiver_profile.id, 
                                          limitby=(0,10), min_length=1, db=db(db.i2l_receiver_profile.user_id==auth.user_id))

使用:

db.letter.opening.widget = suggest_widget(db.receiver.opening, 
                                          limitby=(0,10), min_length=1, db=db(db.i2l_receiver_profile.user_id==auth.user_id))

这意味着不定义“id_field”将阻止它

instead :

db.letter.opening.widget = suggest_widget(db.receiver.opening, id_field=db.i2l_receiver_profile.id, 
                                          limitby=(0,10), min_length=1, db=db(db.i2l_receiver_profile.user_id==auth.user_id))

use:

db.letter.opening.widget = suggest_widget(db.receiver.opening, 
                                          limitby=(0,10), min_length=1, db=db(db.i2l_receiver_profile.user_id==auth.user_id))

that means not defining "id_field" will prevent it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文