In Django models, what does the related_name attribute do?
Correct answer
B. Defines the reverse relationship name
14 views
B. Defines the reverse relationship name
14 views
related_name defines the name of the reverse relationship — the attribute used on the related model to reach back. With related_name="books" on a ForeignKey to Author, you can write author.books.all().
Without it Django uses the default modelname_set.
Want more practice? Try the full set of Computer Science MCQs on MCQsExam.com.
Not sure why the answer is B? Ask here and get an explanation.