Django-NotesApp/project/accounts/serializers.py

14 lines
425 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(
2023-03-03 23:47:30 +08:00
many=True, allow_null=True, queryset=Note.objects.all())
class Meta:
model = User
2023-03-03 23:47:30 +08:00
fields = ['id', 'username', 'notes',]
read_only_fields = ['id', 'notes']