[Answer]-Django templates foreign key traversal

1👍

You can span relationships by accessing the property by using. Django covers this in the documentation

an_event = Events.objects.all()[0]
an_event.system_id_fk.system_id

Your naming convention could be a little confusing because for ForeignKey Fields django automatically creates an _id field on the model:

system_id_fk = models.ForeignKey(Systems)

The above creates a column named system_id_fk_id in the events table in your db. But when you access an_event.system_id_fk it will use the system_id_fk_id column to query the related objeCT!!!

Leave a comment