1

What does '+' value mean, when passed for related_name parameter of models.ForeignKey()?

class Foo(models.Model):
    bar = models.ForeignKey(related_name='+')
niekas
  • 8,187
  • 7
  • 40
  • 58
  • Possible duplicate of [What is \`related\_name\` used for in Django?](https://stackoverflow.com/questions/2642613/what-is-related-name-used-for-in-django) – Yugandhar Chaudhari Feb 27 '19 at 11:16

1 Answers1

2

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 As for a given B, but by setting it to '+', we disable that behavior.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555