Django的链选择 [英] django chain select

查看:194
本文介绍了Django的链选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django的智能选择是一个优雅的解决方案,使Django的开发人员在他们的形式链接选择输入。但在问题清单开发者报告的,它不能很好地工作在表单集使用时。

django-smart-selects is an elegant solution that enables Django developers to have chained select inputs in their forms. But as reported by developers in its list of issues, it does not work well when used in formsets.

它呈现的JavaScript是联系在一起的链式场在模型中定义的ID。

The javascript it renders is tied to the id of the "chained field" right in the model definition.

您如何看待这可在表单集使用时工作?我想呈现小部件的方法(请参阅Django的智能选择code)需要以某种方式被告知表单集的(理想情况下,形式prefixes)。但如何?

How do you think this can be made to work when used in formsets? I think the render method of the widget (please see the django-smart-selects code) needs to somehow be made aware of formsets (and ideally, form prefixes). But how?

推荐答案

我想这和它的作品---在的widgets.py文件Django的智能选择code,简单的复制与交易的部分渲染JavaScript和从文件中删除。卸下连接此(现已删除)的JavaScript输出就行了。

I tried this and it works --- In the widgets.py file of django-smart-selects code, simply copy the section that deals with rendering javascript and delete it from the file. Remove the line that concatenates this (now deleted) javascript to the output.

有关你的表单集,做完整的呈现自己。也就是说,在您的模板不只是做{{形式}}或{{表单集}}或者什么,而是明确地奠定了所有的各个字段通过在{%做{{form.field}}在表单集的形式。构成%}循环。

For your formsets, do the complete rendering yourself. That is, in your template don't just do {{ form }} or {{ formset }} or whatever, but explicitly lay out all individual fields by doing {{ form.field }} in a {% for form in formset.forms %} loop.

粘贴从widgets.py复制的JavaScript code和用的ID在JavaScript中使用自定义{{form.field.html_name}}

Paste the javascript code that you copied over from widgets.py and customize it with the IDs in the javascript with {{ form.field.html_name }}

写在JavaScript创建自己的自定义网址,继在code模式。

Write in your own customized urls in the javascript, following the pattern in the code.

瞧!

这篇关于Django的链选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆