下拉列表之间的同步:Django
我有一个模型
class Location(models.Model):
country = models.ForeignKey('LocationCountry',null = True,blank = True)
city = models.ForeignKey('LocationCity',null = True,blank = True)
locality = models.ForeignKey('LocationLocality',null = True,blank = True)
该模型的表格如下所示,
class LocationForm(ModelForm):
class Meta:
model = Location
国家、城市和地区均为下拉列表。 我想做的是让它们像无线电选择一样,即如果我从国家/地区选择一个项目,那么所选的城市和地点项目应该变为空。 因此在任何情况下都只会选择其中 1 个。 问题清楚吗?任何帮助将不胜感激。
I have a model
class Location(models.Model):
country = models.ForeignKey('LocationCountry',null = True,blank = True)
city = models.ForeignKey('LocationCity',null = True,blank = True)
locality = models.ForeignKey('LocationLocality',null = True,blank = True)
The form for this model is as follows
class LocationForm(ModelForm):
class Meta:
model = Location
Th country,city and locality being FK come as drop down lists.
What i want to do is make them like radio select i.e. if i select an item from country then the city and locality item selected should become null. So at any instance only 1 of them is selected.
Is the question clear ? Any help will be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为(正如托尼在他的评论中提到的)你可以用 Javascript 实现这一点。有很多保管箱影响其他保管箱的示例(例如这个详尽的解释)。我建议您看一下该示例,看看是否可以将其塑造为您想要的行为。如果它不适合您,您也许应该重新表述您的问题,即您在下拉列表之间的同步方面遇到的确切问题。
I think (as tony mentioned in his comment) that you would get there with Javascript. There are plenty of examples of dropboxes influencing other dropboxes (like this thorough explanation). I suggest you take a look at that example, and see if you can mold it to the behavior you want. If it doesn't work out for you, you should perhaps rephrase your question the exact problem you are having with the synchronization between the dropdowns.