Merge pull request #5 from lemeow125/bug/notesperuser

Fixed user serializer error when specifying notes relationship
This commit is contained in:
lemeow125 2023-03-26 13:51:17 +08:00 committed by GitHub
commit d2cd05da33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,9 +5,9 @@ from notes.models import Note
class CustomUserSerializer(serializers.ModelSerializer):
notes = serializers.PrimaryKeyRelatedField(
many=True, allow_null=True, queryset=Note.objects.all())
many=True, allow_null=True, read_only=True)
class Meta:
model = User
fields = ['id', 'username', 'notes',]
fields = ['id', 'username', 'notes']
read_only_fields = ['id', 'notes']