Django 无法暴露';验证用户组';Tastypie用户资源中的表

Django 无法暴露';验证用户组';Tastypie用户资源中的表,django,tastypie,django-authentication,Django,Tastypie,Django Authentication,我一直在努力找出是否有办法公开我的UserResource Tastypie modelResource中的“auth_user_groups”表 我能够获取组和用户,但不确定如何在我的UserResource中显示用户分配到的组。以下是我拥有的模型资源: class GroupResource(ModelResource): class Meta: queryset = Group.objects.all() always_return_data = True reso

我一直在努力找出是否有办法公开我的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()
感谢您的帮助。

如:

ModelResource子类将内省所有非关系字段

因此,必须将“组”字段添加到用户资源:


答案太明显了。:)我想我需要另一种资源。多谢!
class UserResource(ModelResource):
  groups = fields.ManyToManyField(GroupResource, 'groups', null=True, full=True)

  class Meta:
     [...]