[Fixed]-Django: define a name for reverse ForeignKey

31👍

yes, using related_name

class Foo(models.Model):
    foo_field = ...

class Bar(models.Model):
    foo = models.ForeignKey(Foo, related_name="bars", on_delete=models.CASCADE)
    bar_field = ...
👤second

Leave a comment