我有如下的models.py:
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)
如何显示最终存储在班级简介中的老师姓名当我这样做时, 我得到的是_complaint表中的一列teacher_id
student_obj = Student.objects.get(name=user_profile_instance)
接着
compaint = student_obj.complaint_set.values()
在投诉.html
{{complaint.teacher_id}}
我想要的是老师的名字而不是 id