我正在尝试使用具有外键的 POST 保存模型。在我为相关模型设置“添加”、“修改”权限之前,它返回 401 未经授权。简单示例:models.py
class AnotherModel(models.Model):
field = models.TextField()
class MyModel(models.Model):
foreign_key = models.ForeignKey(AnotherModel)
资源.py
class AnoterResource(ModelResource):
class Meta:
queryset = AnoterModel.objects.all()
resource_name = 'another'
authorization = DjangoAuthorization()
authentication = ApiKeyAuthentication()
class MyModelResource(ModelResource):
foreign = fields.ToOneField(AnoterResource, 'foreign_key')
class Meta:
queryset = MyModel.objects.all()
authorization = DjangoAuthorization()
authentication = ApiKeyAuthentication()
allowed_methods = ['get', 'post', 'patch', 'put']
那么,我是否还需要允许 AnotherModel 的“添加”、“修改”权限,以保存 MyModelResource 或者我是否在某个地方弄错了?