1👍
✅
To be able to use logged-in user, you need to access request object first (request.user
)
Here’s an example how you can customize your serializer:
class WidgetListSerializer(EncryptedLookupModelSerializer):
# ...
def __init__(self, *args, **kwargs):
user = kwargs['context']['request'].user
super(WidgetListSerializer, self).__init__(*args, **kwargs)
self.fields['owner'].default = user
self.fields['parent'].queryset = WidgetList.objects.filter(owner=user)
Source:stackexchange.com