Django: what is the difference (rel & field)

PythonDjangoEntity Relationship

Python Problem Overview


What is the difference between Django's models.ManyToManyField and models.ManyToManyRel? I'm confused about this stuff.

Python Solutions


Solution 1 - Python

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!

Solution 2 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsultanView Question on Stackoverflow
Solution 1 - PythonDamonView Answer on Stackoverflow
Solution 2 - PythonDaniel RosemanView Answer on Stackoverflow