我有两个django应用程序与外键关系有关。模型如下:
附录1:型号.py
from django.db import models
from app2.models import Student
class Profile(models.Model):
profile_id = models.IntegerField(primary_key=True)
student_id = models.ForeignKey('app2.Student', null=True, blank=True)
status = models.CharField(max_length=150, null=True, blank=True)
附录2:型号.py
from django.db import models
from app1.models import Profile
class Student(models.Model):
student_id = models.IntegerField(primary_key=True)
first_name = models.CharField(max_length=150, null=True, blank=True)
last_name = models.CharField(max_length=150, null=True, blank=True)
我正在尝试实现反向查找,由于某些原因,我无法得到它。我看过this和this。以下是我在我的api.py
中用json发送的内容:
class studentList(APIView):
def get(self, request, pk, format=None):
student_detail = Student.objects.filter(student_id = pk)
serialized_student_detail = studentSerializer(student_detail, many=True)
return Response(serialized_student_detail.data)
我试图实现的是发送另一个名为status的字段以及上述json值,这些值将包含Profile
模型中的status值。我如何做到这一点?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐