我定义了以下模型
class Flight(models.Model):
...
class FlightUpdate(models.Model):
flight = models.ForeignKey('Flight', related_name='updates')
...
以及以下在REST框架扩展中使用NestedViewsetMixin
的视图集
因此,要访问与Flight
关联的FlightUpdates
,URL是/flights/1/updates/
。在
我想确保只有当人们有权更改与FlightUpdate
关联的Flight
对象时,才能创建FlightUpdates
。在
在添加FlightUpdate
时,如何执行额外的检查?如果我没试着用最好的方式来添加。在
if not request.user.has_perm('flights.change_flight', flight):
raise PermissionError()
注意:我使用django-rules
实现对象级权限。在
我通过实现一个自定义权限类来解决这个问题。在
相关问题 更多 >
编程相关推荐