Django webapp에는 페이지 매김을 사용하여 목록을 표시하는 함수 기반 API가 있습니다. 문제는 목록의 각 행에 관계형 필드의 출력을 확장하고 싶습니다.확장 된 관계형 모델 데이터가있는 장고 쿼리 세트 목록
class Attendance(models.Model):
CHECKIN = 1
CHECKOUT = 2
ATTENDANCE_TYPE_CHOICES = (
(CHECKIN, "Check In"),
(CHECKOUT, "Check Out"),
)
employee = models.ForeignKey(Employee)
company = models.ForeignKey(Company)
activity_type = models.IntegerField(choices = ATTENDANCE_TYPE_CHOICES, default=CHECKIN)
이것은 내가 표시 할 및 페이지 매김 무엇 필드 정의 내 목록 API의 일부입니다
이 출석 내 모델입니다.
employee_list = Employee.objects.filter(company = auth_employee.employee.company.id).values("id","employee","company","activity_type").order_by('id')
page = request.GET.get('page', request.POST['page'])
paginator = Paginator(employee_list, request.POST['page_limit'])
try:
employees = paginator.page(page)
except PageNotAnInteger:
employees = paginator.page(request.POST['page'])
except EmptyPage:
employees = paginator.page(paginator.num_pages)
return Response(list(employees), status=status.HTTP_200_OK)
출력은 이와 같은 목록이지만 직원 세부 정보는 없습니다.
[
{
"id": 14,
"employee": 15,
"company": 15,
"activity_type": 1,
},
{
"id": 15,
"employee": 15,
"company": 15,
"activity_type": 2,
}
]
예상 출력은 어떻게됩니까?
[
{
"id": 14,
"employee": {
"id":"2",
"name":"Michael"
},
"company": 15,
"activity_type": 1,
},
{
"id": 15,
"employee": {
"id":"2",
"name":"Jeniffer"
},
"company": 15,
"activity_type": 2,
}
]
json 응답에 위와 같은 관계형 데이터가 표시되는 목록을 어떻게 만들 수 있습니까?