姜戈 - 你能解释一下吗?
我有三个模型:
System_Contact
System
Contact_list
Contact_List
模型有两个字段: contact
> 和 sys
,毫不奇怪,它只是一个将联系人列表与每个系统关联的多对多模型。我有 modelForm
用于将新联系人添加到系统的联系人列表中:
class Add_Contact_Form(ModelForm):
class Meta:
model = Contact_List
fields = ('contact',)
很简单,对吗?我的困惑是:即使认为 Contact_List
模型有许多很多重复的联系人
(因为一个联系人可以与许多系统关联),每个联系人都是仅在表单的 Select
小部件中显示一次。
为什么?!
我的意思是,对于我的目的来说,这是一个很好的默认行为,但我想确保这实际上是我可以依赖的正确默认行为,而不是我所做的一些随机错误。现在就为我锻炼吧。
I have three models:
System_Contact
System
Contact_list
The Contact_List
model has two fields: contact
and sys
and, not surprisingly, is just a manyToMany model to associate a list of contacts to each system. I have modelForm
for adding a new contact to the system's list of contacts:
class Add_Contact_Form(ModelForm):
class Meta:
model = Contact_List
fields = ('contact',)
Simple, right? My confusion is this: Even thought the Contact_List
model has many many duplicate contacts
(because one contact can be associated with many systems) each contact is only displayed once within the form's Select
widget.
Why?!
I mean, this is a great default behaviour for my purposes, but I want to make sure this is actually the correct default behaviour that I can rely on, not some random error I have done that just happens to work out for me now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并不是说它是默认行为,而是 contact_list 表单中的选择小部件正在显示联系人表中的所有条目。
每个模型都是数据库中的一个表,因此您有 3 个表:
如果这就是您想要做的,您应该具有以下内容:
这意味着 ContactList 表中的每一行都是系统表中的特定计算机与来自的联系人列表之间的关系联系表
It's not that it's default behaviour, it's that the select widget in your contact_list form is displaying all of the entries that are from the contact table.
Every model is a table in the database, therefore you have 3 tables:
If this is what you are trying to do, you should have the following:
This means that every row in the ContactList table is a relationship between a particular machine from the system table and a list of contacts from the contact table