[Answer]-Displaying all photos in Album in list_display

1👍

The problem is this line:

lst = [x.photo.title for x in self.photo_set.all()]

self.photo_set.all() returns a queryset of photos. The variable x is a photo and x.photo is the photo field. Therefore x.photo.title raises AttributeError because the field has no title attribute. Try x.title instead:

lst = [x.title for x in self.photo_set.all()]

If you want to display the output, it would be better to return a string instead of a list:

titles = ", ".join(x.title for x in self.photo_set.all())
return titles

Leave a comment