我正在编写一个django1.7应用程序,它需要根据数据库中存储的合作企业的查询为表单创建一个选择列表。业务列表可以动态更改,表单选择需要在需要时自动重新填充。我创建了一个名为PartneredBusiness的模型,它存储了所有需要的业务信息。我还创建了一个表单:class StartPartneredDeliveryForm(Form):
def __init__(self, *args, **kwargs):
super(StartPartneredDeliveryForm, self).__init__(*args, **kwargs)
self.fields['partnered_business'].choices = \
[(business.id, business.contact.organization_name) \
for business in PartneredBusiness.objects.all()]
destination_address = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Destination'}))
partnered_business = forms.ChoiceField(widget=forms.RadioSelect(), choices=())
这看起来一开始工作得很好,但是如果我向数据库中添加一个新业务,表单显示的partneredbusiness列表似乎不会更新选择列表,直到我通过停止并重新运行python3 manage.py runserver重新启动服务器。在
有人能告诉我这是怎么回事吗?在