1. Home
  2. Computer Science MCQs
  3. Django
  4. In Django models, what does the related_name attribute do?

Added 28 Apr 2024

In Django models, what does the related_name attribute do?

  1. Specifies the database column name
  2. Defines the reverse relationship name Correct answer
  3. Specifies the foreign key constraint
  4. Defines the primary key of the model

Correct answer

B. Defines the reverse relationship name

14 views

MCQSEXAM

Explanation

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.

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Django MCQs

Practise all Django MCQs

Similar MCQs