class BasicInfo(models.Model):
username = models.OneToOneField(User, on_delete=models.CASCADE)
email = models.EmailField(max_length=250)
abstratct=True
class Student(Basicinfo):
#Student class definition
当我查询时:
user=user.objects.get(user="name")
student=Student.objects.get(username=user)
但是:
user.student_set.all() gives error
'用户'对象没有属性'student_set'??
答案 0 :(得分:1)
只需将related_name添加到学生模型即可访问: https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ForeignKey.related_name