0
我正在嘗試在UserResource中添加配置文件數據,但我無法找到實現它的方法。Tastypie - 作爲嵌套資源的配置文件
我調整了幾分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...
如何解決這個任何想法?
謝謝!