Django: what is the difference (rel & field)

Question:

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

Asked By: sultan

||

Answers:

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.

Answered By: Daniel Roseman

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!

Answered By: Damon