【发布时间】:2012-05-10 08:51:44
【问题描述】:
我了解 TastyPie 的基础知识,但自定义 ModelResource 方法让我很困惑。我正在尝试进行 PATCH api 调用来更新用户的密码,并且数据没有通过 set_password() 方法运行,因此使用原始值而不是数据库中的 HASH 进行更新。这是我的模型资源:
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'user'
excludes = ['is_active', 'is_staff', 'is_superuser']
authorization = Authorization()
detail_allowed_methods = ['get', 'post', 'put', 'delete', 'patch']
filtering = {
'username': ALL,
}
authentication = ApiKeyAuthentication()
我假设我需要在这里使用obj_update 方法,但不确定如何格式化它以在用户表中更新实际对象之前通过set_password 方法运行密码。
【问题讨论】: