[Answer]-Tasypie access user object in get_object_list

1👍

After much research I found that I was going about this the wrong way. Tastypie has a function called authorized_read_list and this solves my issue and seems to be the ideal way to solve this type of problem. Since I am trying to filter based on the currently logged in user, this allows you to filter the query based on the current user. I hope this will save someone else a bunch of time. Here is my updated code:

class FooBarResource(ModelResource):
    class Meta:
        queryset = Foo.objects.all()
        resource_name = 'foobar'
        list_allowed_methods = ['get', 'put', 'post', 'delete']
        authentication = ApiKeyAuthentication()
        authorization = Authorization()

    def authorized_read_list(self, object_list, bundle):
        permissions = department_permissions()
        return object_list.filter(userid=bundle.request.user.id)

Leave a comment