I have the following UserViewSet:
class UserViewSet(viewsets.ReadOnlyModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = (CustomObjectPermissions,)
filter_backends = (filters.DjangoObjectPermissionsFilter,)
When using the api browser to view the User list or a User, I get the error DoesNotExist ... ContentType matching query does not exist.
This error does not occur for other viewsets. It appears to be an issue with the django-guardian shortcut get_objects_for_user(). I've read of similar issues and it seems it relates to django-rest passing the permission as unicode (in this case, u'view_user').
What versions of guardian and rest framework? If you subclass the filter and ensure that it passes binary/str values instead does that resolve the issue? Can you trivially reproduce this in a new project?
The issued ended up being that the view_user permission wasn't set for User (painfully obvious in retrospect). Thanks for the helpful prompts.
@mcastle thanks for the follow up.
I'm running into the same issue. I don't understand what the proposed solution is. @mcastle Would you mind elaborating?
Never mind, figured it out. Sorry for the inconvenience.
@mcastle i'm facing the same issue and I saw your answer here http://stackoverflow.com/questions/7724265/how-to-add-custom-permission-to-the-user-model-in-django as well. I simply added the code to my django project __init__.py. Is there anything else to do?
Most helpful comment
The issued ended up being that the view_user permission wasn't set for User (painfully obvious in retrospect). Thanks for the helpful prompts.