[Answered ]-How to display value of a field in a *linked* table, in a Django template?

2đź‘Ť

âś…

The problem is your field names. For some reason, you’ve called your foreign keys from AlbumSong “song_id” and “album_id”. So you should use the same names in the template: {{ album_song.song_id.name }}.

However, it doesn’t make sense to use this name. The Django field does not represent an ID, it represents the actual Song object. Django already creates an underlying database field with an “_id” suffix, so in this case it’s created one called “song_id_id”, which is silly. Rename your fields “song” and “album”, and keep your template the way it is.

Leave a comment