mirror of
https://github.com/lemeow125/Django-NotesApp.git
synced 2025-05-16 11:38:11 +08:00
Added a custom user serializer to allow sorting of notes by user
This commit is contained in:
parent
65ad4a5f21
commit
ff7934407a
5 changed files with 23 additions and 2 deletions
12
project/accounts/serializers.py
Normal file
12
project/accounts/serializers.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
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, queryset=Note.objects.all())
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['id', 'username', 'notes']
|
Loading…
Add table
Add a link
Reference in a new issue