[Answered ]-Django get attribtues of foreign key

2👍

Here’s an even easier way!

>>> course = Course.objects.filter(name= nameAndNumberStore[0] + nameAndNumberStore[1])
>>> links = course.link_book_course_set.all()
>>> BookAuthorNames = [(link.book.title, link.book.author) for link in links]
(('Book1','Author1'),('Book2','Author2'),...)

Remember, the django ORM is powerful!

👤Thomas

Leave a comment