Django:有什么区别(rel 和 field)
Django 的 models.ManyToManyField
和 models.ManyToManyRel
之间有什么区别?我对这个东西很困惑。
What is the difference between Django's models.ManyToManyField
and models.ManyToManyRel
? I'm confused about this stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ManyToManyRel 由 ManyToManyField 用于实现其扩展的 Field 基类的关系对象。如果您要创建一个扩展 Field 类并包含多对多关系的新字段类,您可能会发现此类很方便,但不应在您的模型中使用它(您将在其中看到弹出建议)如果您的编辑器列出了可用的调用)。
请参阅类字段@:
https://github.com/django/django /blob/master/django/db/models/fields/__init__.py
类ManyToManyRel &类ManyToManyField @:
https://github.com/django/django /blob/master/django/db/models/fields/lated.py
我很高兴这里的绝大多数问题都是可以通过查看参考资料和文档来回答的问题。研究和分享想法以及挖掘“不供外部使用”的代码是很有趣的。我知道如何开始回答这个问题,如果我不知道,我就不会写任何东西。伙计,问得好!
ManyToManyRel is used by the ManyToManyField to implement the relationship object for the Field base class which it extends. If you were to create a new field class that extended the Field class and contained a many-to-many relationship you might find this class convenient but it should not be used in your models (which is where you will see the pop-up suggestion if your editor lists available calls).
See class Field @:
https://github.com/django/django/blob/master/django/db/models/fields/__init__.py
class ManyToManyRel & class ManyToManyField @:
https://github.com/django/django/blob/master/django/db/models/fields/related.py
I am glad that the vast majority of the questions here are questions that can be answered by looking at reference material and documentation. Researching and sharing ideas and digging into code that is "not for external use" is the fun. I know how to start answering this question, if i didn't i would not have written anything. Good question dude!
如果您通过深入研究源代码发现了 ManyToManyRel,则可以阅读该类的文档字符串。它没有在任何地方记录 - 故意的,因为它不供外部使用。它当然不是为了定义模型之间的实际字段关系。
If you discovered ManyToManyRel by digging into the source code, you can read the docstrings for the class. It's not documented anywhere - on purpose, because it's not for external use. It is certainly not meant for defining actual field relationships between models.