Get instance of foreign key – Django Rest Framework

This is what I have: models.py class Subject(models.Model): name = models.CharField(max_length=50) schedule1 = models.CharField(max_length=30, default=”No Schedule”) schedule2 = models.CharField(max_length=30, null=”No Schedule”) def __str__(self): return self.name class Exam(models.Model): date = models.DateTimeField() result = models.FloatField(default=0) subject = models.ForeignKey(Subject, on_delete=models.CASCADE) serializers.py class SubjectSerializer(serializers.ModelSerializer): id = serializers.ReadOnlyField() class Meta: model = Subject fields = ‘__all__’ class TodoSerializer(serializers.ModelSerializer): id =…

Details