display foreignkey field in django template -


i have models.py below:

class profile(models.model):      user = models.onetoonefield(user)      def __unicode__(self):         return "%s" % self.user  class student(models.model):      user = models.foreignkey(profile)     phone_num = models.charfield(max_length=15)      def __unicode__(self):         return "%s" % (self.user)  class teacher(models.model):      user = models.foreignkey(profile)     phone_num = models.charfield(max_length=15)      def __unicode__(self):         return "%s" % (self.user)  class complaint(models.model):      user = models.foreignkey(student)     complaint = models.textfield()     teacher = models.foreignkey(teacher, null=true)       def __unicode__(self):         return "%s : %s" % (self.complaint) 

how can display teacher's name stored in class profile column teacher_id in _complaint table when do

student_obj = student.objects.get(name=user_profile_instance) 

and then

compaint = student_obj.complaint_set.values() 

in complaint.html

{{complaint.teacher_id}} 

what want teacher name instead of id

this should work -

{{ complaint.teacher.user.user.first_name }} 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -