Django 身份验证和权限:仅对创建者可见的片段

Django Authentication and Permissions: Snippets visible only to the creator

因此在身份验证和权限教程中:

http://www.django-rest-framework.org/tutorial/4-authentication-and-permissions/

所有用户都可以看到所有片段,但只允许用户编辑自己的片段。

但我想将程序稍微调整一下:

用户只能看到自己的片段。其他人创建的片段不可见。

这可能吗?

是的,这是可能的。看看filtering querysets。简而言之,您必须编写自己的 get_queryset 方法以仅 return 与登录用户关联的结果。