我有以下用户资源代码,如何插入返回用户权限列表的'权限字段'
?
class UserResource(ModelResource):
user_permissions = fields.ToManyField #??????
class Meta:
queryset = User.objects.all()
resource_name = 'user'
authorization = Authorization()
always_return_data = True
list_allowed_methods = ['get', 'post', 'put', 'delete']
authorization = DjangoAuthorization()
authentication = MultiAuthentication(BasicAuthentication(), SessionAuthentication())
filtering = {
"date_joined": ALL,
"email": ALL,
"first_name": ALL,
"is_active": ALL,
"is_staff": ALL,
"is_superuser": ALL,
"last_login": ALL,
"last_name": ALL,
"username": ALL,
"user_permissions": ALL_WITH_RELATIONS,
}
最佳答案
如果你使用 django-tastypie 它可以像这样没有字段的情况下工作。
class UserResource(ModelResource):
class Meta:
# your definitions
def dehydrate(self, bundle):
# Include user permissions
bundle.data['user_permissions'] = bundle.obj.user_permissions()
return bundle
关于python - 如何在用户资源中插入 user_permissions 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32236890/