在我的 Django 應用程序中,我寫了一個帶有forms.ChoiceField的表單 。選擇應該是我的數據庫中每幾分鐘更改一次的項目列表。當我重新加載頁面時,我希望在下拉按鈕中顯示當前的項目列表。我的代碼運行良好,除了 forms.ChoiceField 不更新。要更新,我必須重新啟動 Django 服務器。我不知道我錯過了什么,你能幫我嗎?一定是小東西。來自forms.pyclass BookingForm(forms.ModelForm): make_list_of_tuple = lambda list_machine : [tuple( [i,i]) for i in list_machine] MACHINES= tuple( QA_machine_DB.objects.values_list('QAmachine',flat=True)) CHOICE_QA_MACHINES= make_list_of_tuple(MACHINES) QAmachine= forms.ChoiceField(choices=CHOICE_QA_MACHINES) class Meta(): model= QA_machine_DB fields= ['QAmachine', 'owner', 'comments','status'] # http://nanvel.name/2014/03/django-change-modelform-widget widgets = { 'owner':forms.TextInput(attrs={'placeholder':'owner'}), 'comments':forms.TextInput(attrs={'placeholder':'comments'}), 'status': forms.RadioSelect( choices=[('busy','busy'),('free','free')])}從模板<form class="form-group" method="post" novalidate > {% csrf_token %} <table > <td> {{ BookingForm.QAmachine}} </td> <td> {{ BookingForm.owner.errors }} {{ BookingForm.owner}} </td> <td> {{ BookingForm.comments.errors }} {{ BookingForm.comments}} </td> <td> {% for radio in BookingForm.status %} {{ radio }} {% endfor %} </td> </table> <input type="submit" class="btn btn-success" value="submit status change" style="float: right;" > 坦克你在Advance
添加回答
舉報
0/150
提交
取消