我们想在特定学校中使用create view创建一个学生,如何访问学校的主键(id)?
class School(models.Model):
name = models.CharField(max_length = 264)
principal = models.CharField(max_length = 264)
location = models.CharField(max_length = 264)
class Student(models.Model):
name = models.CharField(max_length=264)
age = models.PositiveIntegerField()
school = models.ForeignKey(School, on_delete=models.CASCADE,
related_name = 'students')
当我们不知道如何将学生模型与学校模型联系起来时,如何定义get_absolute_url(self):
?