Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: what is the difference (rel & field)

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

like image 263
sultan Avatar asked Mar 07 '11 07:03

sultan


People also ask

What is ManyToManyRel in Django?

ManyToManyRel is used by the ManyToManyField to implement the relationship object for the Field base class which it extends.

What is Relatedmanager Django?

A “related manager” is a manager used in a one-to-many or many-to-many related context. This happens in two cases: The “other side” of a ForeignKey relation. That is: from django.db import models class Blog(models.

How do I create a ForeignKey in Django?

What is ForeignKey in Django? ForeignKey is a Field (which represents a column in a database table), and it's used to create many-to-one relationships within tables. It's a standard practice in relational databases to connect data using ForeignKeys.


1 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!

like image 184
Damon Avatar answered Oct 02 '22 01:10

Damon