Data structures, not algorithms, are central to programming. 알고리즘이 아니라, 자료구조가 프로그래밍의 중심이다.

관계 필드는 모델 관계를 표현하기 위해 사용된다. 관계 필드는 ForeignKey, ManyToManyField, 그리고 OneToOneField 관계에 사용되고, 또 역참조 관계와 GenericForeignkey 같은 커스텀 관계에도 사용된다.

Note: 관계 필드는 relations.py에 선언되지만, 컨벤션에 따라 반드시 from rest_framework import serializers를 사용해 serializers모듈에서 임포트해와야 하고, serializers.<FieldName> 같이 필드를 참조해야 한다.

Inspecting Relationships

ModelSerializer 클래스를 사용할 때, 직렬화된 필드와 관계는 자동적으로 생성된다.

API Reference


StringRelatedField


PrimaryKeyRelatedField


HyperlinkedRelatedField


SlugRelatedField