What does '+'
value mean, when passed for related_name
parameter of models.ForeignKey()
?
class Foo(models.Model):
bar = models.ForeignKey(related_name='+')
What does '+'
value mean, when passed for related_name
parameter of models.ForeignKey()
?
class Foo(models.Model):
bar = models.ForeignKey(related_name='+')
As the Django documentation on related_name
says:
If you’d prefer Django not to create a backwards relation, set
related_name
to'+'
or end it with'+'
.
If you thus have two models A
and B
, then by setting a ForeignKey
from A
to B
, Django will add a manager to B
to obtain all related A
s for a given B
, but by setting it to '+'
, we disable that behavior.