What is the difference between Django's models.ManyToManyField
and models.ManyToManyRel
? I'm confused about this stuff.
-
1do you want to change django itself? – Mar 07 '11 at 09:40
-
2@hop nope it's just about natural interest) – sultan Mar 07 '11 at 10:59
-
we also know that if you select `ManyToManyField` than an additional table is created, but `ManyToManyRel` – sultan Mar 07 '11 at 12:58
2 Answers
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!

- 936
- 7
- 3
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.

- 218,210
- 55
- 464
- 476

- 588,541
- 66
- 880
- 895
-
11I've looking over the sources and figured out that `ManyToManyRel` is used for relation lookup by `ManyToManyField`. Also I follow the actual documentation as accurate as possible). – sultan Mar 08 '11 at 06:32
-
106Just a heads up, the asker could have seen it pop up in an ide's auto complete box. – George Griffin Oct 13 '11 at 02:50
-
16If we always stuck to just the docs, most of us would be really lost. – explodes Apr 19 '12 at 18:02
-
12I had the same question using Eclipse + PyDev and finding the undocumented ManyToManyRel suggestion. It's not a trivial question at all. – chirale Oct 17 '12 at 12:16
-
3Wow... because of this answer I just realized there are no private methods (or anything else) in Python. Crazy, I tell you, crazy! – Eduard Luca Jun 16 '13 at 21:58
-
1@George Griffin, it did happen to me too. A popup which suddenly confuses as to what the correct choice is. – unlockme Aug 22 '16 at 19:04