본문 바로가기
WIL&TIL/TIL

20230605 TIL - Serializer - depth, repr()

by 코드뭉치 2023. 6. 5.

 

1️⃣ Serializer - depth, repr()

 

[DRF] Serializer - depth, repr()

1️⃣depth Article이 "title", "content", "author" 필드를 가지고 있고, 이 중 author 필드가 user와 ForeignKey관계라고 가정. class Article(models.Model): title = models.CharField ... content = models.CharField ... author = models.Foreig

codemte.tistory.com

 

 

2️⃣ ModelSerializer와 CreateModelMixin 사용하기

 

[DRF] ModelSerializer와 CreateModelMixin 사용하기

ModelSerializer 기본적으로 Serializer를 상속. .create() 및 .update() 메소드 제공 serializer에 대한 validator(예: unique_together validator)를 자동으로 생성 예시) title과 content가 있는 Article 모델 from django.db import mod

codemte.tistory.com

 

 

3️⃣ GenericAPIView와 Mixins

 

[DRF] GenericAPIView와 Mixins

DRF에서는 GenericAPIView와 다양한 Mixin 클래스를 결합해 APIView를 구현할 수 있다. 1️⃣ GenericAPIView GenericAPIView는 queryset과 serializer_class를 지정해줄 수 있다. queryset - View에서 객체를 반환하는 데 사용

codemte.tistory.com

 

'WIL&TIL > TIL' 카테고리의 다른 글

20230608 TIL - Permissions  (0) 2023.06.09
20230607 TIL - Postman AccessToken 자동 갱신하기  (0) 2023.06.07
20230602 TIL - 알고리즘  (0) 2023.06.02
20230601 TIL - 알고리즘  (0) 2023.06.01
20230531 TIL - 배포 중 만난 에러 정리  (0) 2023.06.01

댓글