[Fixed]-Django restricting access to view for certain objects

1👍

You could do that in get method to block/allow access:

from django.core.exceptions import PermissionDenied

def get(self, request, *args, **kwargs):
    team_id = self.kwargs.get('team_id')
    team = team_model.objects.get(pk=team_id)
    if team.name != TEAM_NAME: 
        raise PermissionDenied
    else:
        return super(PlayerList, self).get(request, *args, **kwargs)

Leave a comment