我一直在努力找出是否有办法在我的 UserResource Tastypie modelResource 中公开“auth_user_groups”表。
我能够获取组和用户,但不确定如何在我的 UserResource 中显示用户分配到的组。这是我拥有的模型资源:
class GroupResource(ModelResource):
class Meta:
queryset = Group.objects.all()
always_return_data = True
resource_name = 'groups'
detail_allowed_methods = ['get']
list_allowed_methods = ['get']
filtering = {
'username': ALL,
}
authentication = ApiKeyAuthentication()
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
always_return_data = True
resource_name = 'user'
excludes = ['is_active', 'is_staff', 'is_superuser']
authorization = UserAuthorization()
detail_allowed_methods = ['get', 'post', 'put', 'delete', 'patch']
list_allowed_methods = ['get', 'post', 'put', 'delete', 'patch']
filtering = {
'username': ALL,
}
authentication = ApiKeyAuthentication()
谢谢你的帮助。