TIL(22.12.06) - Django source

이지영·2022년 12월 6일
0

TIL/WIL

목록 보기
83/110

에러 발생 이유

AttributeError: Got AttributeError when attempting to get a value for field `review_set` on serializer `PublicProfileSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `Profile` instance.
  • Profile이라는 모델이 따로 생성되어있어, User 모델과 연결되어있는 Review 리스트를 가져오려고 하니 에러 발생

해결

review_set = ReviewListSerializer(many=True, source='user.review_set')
  • source를 이용한다
  • source='user.review_set'
  • profile 관련 serializer에서도 내가 작성한 리뷰리스트를 조회 할 수 있다.
  • profile에서 user의 review를 타고타고 들어가서 가져오기 가능!
profile
🐶🦶📏

0개의 댓글