Django MultipleChoice 条目未刷新
我有一个多选小部件,它从 mysql 数据库获取数据并向用户显示。
list = [(x.pk, x.parameter) for x in Parameter.objects.all()]
parameters = forms.CharField(label=("Available parameters"),widget=forms.SelectMultiple(choices=list)
例如,目前它的选择会显示为[A,B,C]。
如果我直接从数据库中删除“B”,我应该只能在 selectmultiple 小部件中看到 [A,C](最初我以为会重新加载并再次从数据库获取数据),但这似乎不是如果是这样的话,它仍然会显示[A,B,C]。我希望 selectmultiplet 小部件在运行时实际显示当前数据库,或者至少刷新(F5)页面{似乎也不刷新小部件}。如果我重新启动网络服务器,它只会获取新的数据集。
我想这可能是我需要清除的一些缓存?感谢任何建议。 谢谢
I have a selectmultiple choice widget that gets data from mysql database and displays to the user.
list = [(x.pk, x.parameter) for x in Parameter.objects.all()]
parameters = forms.CharField(label=("Available parameters"),widget=forms.SelectMultiple(choices=list)
For example, currently it will show like [A,B,C] in its choices.
If I delete 'B' directly from the database, I should be able to see only [A,C] in the selectmultiple widget(initially I thought there will be a reload and get data from database again), but that doesn't seem to be the case, it will still display [A,B,C]. I want the selectmultiplet widget to actually show the current database at runtime, or refresh(F5) the page at least {seems to not refresh the widget too}. It will only get the new set of data if I restart the web server.
I think it might be some cache that I need to clear? Appreciate any suggestions.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将代码放入表单的 init 方法中,或者在创建表单时将选项传递给表单:
You need to put your code in the init method of the form, or pass the choices to the form on form creation: