Created
September 3, 2011 02:19
-
-
Save jorilallo/1190426 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EnvironmentResource(ModelResource): | |
class Meta: | |
queryset = Environment.objects.all() | |
resource_name = 'environment' | |
list_allowed_methods = ['get', 'post'] | |
authentication = ApiKeyAuthentication() | |
authorization = Authorization() | |
def obj_create(self, bundle, request=None, **kwargs): | |
return super(EnvironmentResource, self).obj_create(bundle, request, user=request.user) | |
def apply_authorization_limits(self, request, object_list): | |
# request here is None which fails | |
return object_list.filter(user=request.user) | |
class AnotherEnvironmentResource(ModelResource): | |
list = fields.ForeignKey(EnvironmentResource, 'env', null=True) | |
class Meta: | |
queryset = AnotherEnvironment.objects.all() | |
resource_name = 'environment' | |
list_allowed_methods = ['get', 'post'] | |
authentication = ApiKeyAuthentication() | |
authorization = Authorization() | |
def obj_create(self, bundle, request=None, **kwargs): | |
return super(AnotherEnvironmentResource, self).obj_create(bundle, request, user=request.user) | |
def apply_authorization_limits(self, request, object_list): | |
return object_list.filter(user=request.user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment