TIL day-59 drf

yo·2020년 8월 24일
0

-serializer에 instance 여러개(query set)넣을 땐 many=True설정하기

It's important to remember that ModelSerializer classes don't do anything particularly magical, they are simply a shortcut for creating serializer classes:
1)An automatically determined set of fields.
2)Simple default implementations for the create() and update() methods.

by drf docs

Wrapping API views

REST framework provides two wrappers you can use to write API views.
The @api_view decorator for working with function based views.
The APIView class for working with class-based views.

request.data

request.data를 통해 json데이터를 처리할 수 있게 되고, 심지어 다른 데이터 타입도 받을 수 있게 된다.
response 또한 올바른 content type으로 변환되어 처리된다.

Notice that we're no longer explicitly tying our requests or responses to a given content type. request.data can handle incoming json requests, but it can also handle other formats. Similarly we're returning response objects with data, but allowing REST framework to render the response into the correct content type for us.

serializers, ReadOnlyField

ReadOnlyField is always read-only, and will be used for serialized representations, but will not be used for updating model instances when they are deserialized. We cou

profile
Never stop asking why

0개의 댓글