I'm using Django with Django REST and have a user permission system based on user groups. As a result I have to check assigned user groups a few times inside views to see if a user belongs to a certain group using request.user.groups.all(). It works but every such call results in an extra query to db to retrieve groups.
I wish I could override some method that pulls a user from a db during authentication before attaching it to a request, so I can add something like
User.objects.get(pk=userid).prefetch_related('groups')
so no extra calls would be made whenever I access groups further down.