0Pricing
Django Academy · Lesson

related_name and Reverse Lookups

Traverse relationships in both directions.

Links Go Both Ways

You set a ForeignKey from book to author, but you can also walk it backward. A reverse lookup reaches the many side from the one side.

The Default _set Manager

By default Django names the reverse accessor modelname_set. From an author, the books appear as book_set.

author = Author.objects.first()
author.book_set.all()

All lessons in this course

  1. ForeignKey and on_delete
  2. ManyToManyField and Through Models
  3. OneToOneField for Profiles
  4. related_name and Reverse Lookups
← Back to Django Academy