我正在尝试在 UserResource 中添加配置文件数据,但我找不到这样做的方法。
我对docs上的代码进行了一些调整,如下所示:
class UserResource(ModelResource):
profile = fields.ForeignKey(UserProfile, 'profile', full=True)
class Meta:
queryset = User.objects.all()
resource_name = 'user'
excludes = ['email', 'password', 'is_active', 'is_staff', 'is_superuser']
#authentication = BasicAuthentication()
authorization = DjangoAuthorization()
def dispatch(self, request_type, request, **kwargs):
kwargs['profile'] = request.user.get_profile()
return super(UserResource, self).dispatch(request_type, request, **kwargs)
但是给了我这个错误:
error_message: Cannot resolve keyword 'profile' into field. Choices are: date_joined, email, first_name, groups, id, is_active, is_staff, is_superuser, last_login, last_name, logentry, password...
知道如何解决这个问题吗?
谢谢!