有人可以帮我解决这个ManyToManyField问题
MODELS.PY
class Course(models.Model):
course_code = models.CharField(max_length=8, unique=True)
course_name = models.CharField(max_length=128, unique=True)
is_active = models.BooleanField(default=True)
def __str__(self):
return self.course_code
class Degree(models.Model):
degree_code = models.CharField(max_length=16, unique=True)
degree_name = models.CharField(max_length=128, unique=True)
courses = models.ManyToManyField(Course)
is_active = models.BooleanField(default=True)
def __str__(self):
return self.degree_code
现在我查询
>>> Degree.objects.values_list('courses')
[(4,), (3,), (1,), (5,), (4,), (3,), (2,), (1,)]
我正在获取ID,如何获取课程名称而不是ID?
答案 0 :(得分:1)