models.朋友
class InfraServiceInfo(db.Model):
app_name = db.CharField(choices=VIEW_APP_CHOICES, max_length=1000)
stack = db.CharField(max_length=1000)
description = db.TextField('InfraServiceInfo', choices=VIEW_DESC_CHOICES)
需要说明的是,在该InfraServiceInfo表中的每个APP_NAME相关。作为APP_NAME是下拉列表中,当选择一个特定APP_NAME与APP_NAME相关联的对应的描述应当被自动在形式填充。
例如:APP_NAME = “测试”,描述= “测试” 和APP_NAME = “test2的”,描述= “testing2”。当从下降downlist用户选择测试,描述应自动填充测试字符串。我该怎么做呢?
我认为你需要奉献不同url
以满足您的选择InfraServiceInfo
,在那里你可以显示所选的描述。
说你的网址是像
urlurl(r'^infraServiceInfo/$', 'myapp.views.infraServiceInfo', name='InfraServiceInfo'),
url(r'^infraServiceInfo/(?P<slug>[\w-]+)/$', 'myapp.views.infraServiceInfo_detail', name='InfraServiceInfo_detail'),
而在你infraServiceInfo_detail
def infraServiceInfo_detail(request, app_name):
description = InfraServiceInfo.objects.get(app_name=app_name).description
app_names = InfraServiceInfo.objects.values_list('app_name', flat=True)
return render(request, 'your_render.html', {'description': description, 'app_names': app_names})