Fixed user serializer error when specifying notes relationship

This commit is contained in:
keannu125 2023-03-26 13:49:19 +08:00
parent bad4d4d647
commit a64294a5a8

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']