Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KimSoungRyoul/a14073248c0780f7022545c074060b9f to your computer and use it in GitHub Desktop.
Save KimSoungRyoul/a14073248c0780f7022545c074060b9f to your computer and use it in GitHub Desktop.
from django.contrib.auth.models import User
from drf_spectacular.utils import OpenApiExample, extend_schema_serializer
from rest_framework.serializers import ModelSerializer
@extend_schema_serializer(
exclude_fields=("password",),
examples=[
OpenApiExample(
"Valid example 1",
summary="short summary",
description="longer description",
value={
"is_superuser": True,
"username": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_staff": False,
"is_active": True,
"date_joined": "2021-04-18 04:14:30",
"user_type": "customer",
},
request_only=True, # view Layer에서 사용한 Example Object와 동일한 동작을 한다.
response_only=False,
),
],
)
class UserReadOnlySerializer(ModelSerializer):
class Meta:
model = User
depth = 1
fields = "__all__"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment