Django-NotesApp/project/accounts/serializers.py

14 lines
411 B
Python
Raw Normal View History

from django.contrib.auth.models import User
from rest_framework import serializers
from notes.models import Note
class CustomUserSerializer(serializers.ModelSerializer):
notes = serializers.PrimaryKeyRelatedField(
many=True, allow_null=True, read_only=True)
class Meta:
model = User
fields = ['id', 'username', 'notes']
2023-03-03 23:47:30 +08:00
read_only_fields = ['id', 'notes']