我希望我的“位置”下拉列表依赖于我的“客户”下拉列表。我的模特:
class Client(models.Model):
name = models.CharField(max_length=50)
class Location(models.Model):
name = models.CharField(max_length=50)
此后的下一步是什么?
我应该把FK放在哪里吗?
什么是AJAX代码?
答案 0 :(得分:0)
如果您要显示两个下拉菜单,第一个带有<ul style="list-style-type: none;margin: 0;padding: 0; color:color:#ff00ff; background-color:darkblue">
<li style=display:inline;> <a href="" style="color:white"> Home </li>
<li style=display:inline;> <a href="" style="color:white"> Education </li>
<li style=display:inline;> <a href="" style="color:white"> Work Experience </li>
<li style=display:inline;> <a href="" style="color:pink"> Hobbies </li>
</ul>
<article>
<p> BLANK is a student at BLANK <br> He is currently enrolled in the Computer Information Systems <br> program at the school. He is expected to graduate in 2019. </p>
</article>
选项,第二个带有Client
选项,而Location
的{{1}}下拉更改则应添加一个js事件处理程序,例如jQuery:
Locations
在后端,将Client
模型附加到$(document).on('change', '#clients', () => {
...call locations endpoint and update locations options...
})
FK上,并为路径Location
创建端点,在该端点上,您根据Client
选择app/locations/<int:client_id>/
:< / p>
Locations