问题标签 [choicefield]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
50 浏览

django - 根据 Django 中的选择呈现新字段

我现在正在处理一个 Django 项目,当添加一个 Right 模型时,我希望表单看起来不同,具体取决于属性“type”中选择的内容。这是我的代码:

模型.py

)

我正在考虑某种逻辑,以便根据选择的“类型”添加新字段。有人可以帮我吗?我搜索了文档,但找不到任何对我有帮助的东西。

谢谢!

0 投票
2 回答
1408 浏览

python - Django 1.6 名称选择未定义

我正在尝试在模板中显示下拉菜单,但出现以下错误

这是我试图显示表单的模板

这是forms.py

0 投票
4 回答
128047 浏览

python - Django 选择字段

我正在尝试解决以下问题:

我有一个只能看到版主的网页。此页面上显示的字段(用户注册后):
用户名、名字+姓氏、电子邮件、状态、相关性等。

我需要使用此字段显示存储在 db 中的所有用户信息的表格,但其中两个字段有选择,所以我想选择版主可以选择另一个选项,点击“更新”按钮后,此字段将更新选定的用户。

我可以显示“状态”和“相关性”字段的所有选择,并在我从下拉数据库中选择新选项后更新。
我想显示下拉菜单,并且应该选择存储在 db 中的选项。我尝试了很多选项,我用谷歌搜索了很多时间,并在 StackOverFlow 中搜索答案或正确的方向,但没有找到任何东西。

抱歉我的英语不好,提前感谢您的帮助!

以下是我的部分代码:

模型.py

表格.py

视图.py

模板:


下面是一个解决方案:

forms.py (正如@Liarez 所写)。

模板:

0 投票
1 回答
1512 浏览

python - 禁用除默认选项以外的所有选项 - ChoiceField Django Forms

所以基本上这就是我想要做的:

我想有一种方法能够根据用户使某些字段只读。

到目前为止这很容易,但问题来了,我需要将一些选择输入设为只读,而且……它们不适用于只读。问题是即使没有提交新值,用户仍然可以使用它。我希望禁用选择字段,但如果我这样做,则不会通过 POST 发送值,并且表单有效方法存在问题。

所以在阅读之后,我明白唯一的方法是禁用除了默认选择的字段之外的所有字段?

这怎么可能

这是我到目前为止所拥有的:

这是我要禁用选择的地方....

非常感谢你的帮助,阿拉

0 投票
1 回答
570 浏览

python - Django - 按属性将查询划分为子组

我有一个看起来像这样的模型:

在我看来,我正在按用户过滤条目,如下所示:

我现在要做的是ListEntry.objects.filter(user=self.user_profile)根据status属性将此查询 () 拆分为子组,因此呈现的模板如下所示:

我知道我可以做类似的事情:

依此类推,并遍历模板中的键。或者(在模板中):

但是,是否有一种更好、优化的方法来做到这一点,而无需每次按状态获取子查询时都访问数据库,并且无需多次迭代对象列表?

0 投票
2 回答
2116 浏览

python - Dynamically populating choicefield in Django

I can't initialize the Choicefield form inside the views.py. I tried passing the option variable in the __init__ function but I got an error:

forms.py

views.py

EDIT

I tried Hasan solution and Django Form Wizard is passing {'files': None, 'prefix': 'step2', 'initial': {}, 'data': None} into the **kwarg in the __init__ function of SomeForm.

I printed the content in the **kwarg and I got:

{'files': None, 'prefix': 'step2', 'initial': {}, 'data': None} {'choices': [<Choice: Blue>, <Choice: Red>]}

0 投票
1 回答
1104 浏览

java - Adding a selection to the Choice list in the 'paint' method is adding multiple records of the same in the list

I have created an applet with two choice controls. One of the choice control is the OS name and the other is the browser name. I have added the item listeners for both these choice controls, so that we can detect the option selected for each of the choice control. The code adds another OS entry ("Windows 10")in the OS choice control if the browser selected in Firefox.

Somehow when I select the browser as firefox , multiple entries of "Windows 10' are added in the OS choice control.

Can someone please help me?

SingleClick

OSBrowserSelector

0 投票
2 回答
1037 浏览

django - 如何使用Django中的数据库动态加载ChoiceField的字段?

就像答案一样,我想在选择字段中动态加载数据库,我已经这样做了

但它不起作用,我必须重新启动服务器,才能更新该字段。

0 投票
1 回答
324 浏览

php - 在 Symfony2 中验证选择列表

我有一个选择列表,用户可以在其中选择一个值,但如果用户没有选择任何内容,我什至会设置一个空值。

表单没有模型,可以使用@Assert 注释,并且选择字段是可选的,所以在某些情况下它会被隐藏,只有在向用户显示时才需要验证。

我如何验证这个字段?当我在表单类型中将其设置为 required 时,它没有帮助(如果我是正确的,默认情况下 required 等于 true)。我的问题在哪里?

0 投票
1 回答
3639 浏览

django - 如何从视图将值传递给 Django Form 的 init 方法?

表格.py

现在,我有一个 views.py 文件,它有一个类