CuriousCI
04/30/2022, 5:10 PMclass DonationViewSet(viewsets.ModelViewSet):
queryset = Donation.objects.all()
serializer_class = DonationSerializer
@verify_session()
async def get_queryset(self):
session: SessionContainer = self.request.supertokens
user_id = session.get_user_id()
return Donation.objects.filter(user_id_id=user_id)
'coroutine' object is not iterable
edit 1
I fixed this problem, I had to import verify_session from syncio, not asyncio, and remove the async keyword, but I got into another problem: verify_session is looking for the parameter request, but it is inside 'self'
edit 2
I copied the implementetion of verify_session for Django, and it works
edit 3
The best solution I found was creating another function inside the function to verify the session and return it (with @verify_session()), much cleaner
class DonationViewSet(viewsets.ModelViewSet):
queryset = Donation.objects.all()
serializer_class = DonationSerializer
def get_queryset(self):
@verify_session()
def verify(request):
return request.supertokens
session = verify(self.request)
user_id = session.get_user_id()
return Donation.objects.all(user_id_id=user_id)
I wrote this process, for everyone using Django REST framework like in my case.