avafab
avafab

Reputation: 1701

Django: best way to accessing a ForeignKey value from template

A Card model has many Workouts models (ForeignKey to Card), each Workout model has many Exercise names models (ForeignKey to Workout). I would like to access Exercise Name value in the template. Which is the best way?

Upvotes: 0

Views: 49

Answers (1)

krs
krs

Reputation: 4154

First please edit your question to use the proper "ForeignKey to X", its hard to tell what your FKs go.

But to answer your question, foo_id is the integer represenation of the foo FK field.

that is, print record.exercise will call __unicode__() on the exercice model to get the represenation to print, print record.exercise_id will print the actual FK id.

Upvotes: 1

Related Questions