What this thread does
Do first: require IsAuthenticated and make get_queryset() filter by self.request.user before any list pagination or detail lookup.
Short answer
As of November 2026, use current DRF API docs; the earlier Django integration baseline is DRF 3.16.1 (dated release notes). Combine a caller-filtered queryset, an owner object permission, a read-only owner field and bounded pagination.
Choose / don't choose
- PageNumberPagination: choose for numbered pages and modest, relatively stable lists; don't promise a stable browsing snapshot while new rows arrive.
- CursorPagination: choose for a growing feed; use an indexed, unchanging, non-null, unique or nearly unique ordering field. Default ordering is
-created; define it for your actual model. It avoids repeated items during insertion when used correctly, but does not provide arbitrary page jumps (pagination).
Not for: passkey enrollment and login; see passkey-webauthn-rails-django-fastapi-ceremonies.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
DEFAULT_PERMISSION_CLASSES | ['rest_framework.permissions.IsAuthenticated']; omitted configuration defaults to AllowAny | Current DRF docs | permissions |
permission_classes | [IsAuthenticated, IsOwner], with application-defined IsOwner; replaces global defaults | Current DRF docs | permissions |
get_queryset() | Filter the queryset to return results relevant to the currently authenticated user | Current DRF generic views | filtering |
DEFAULT_PAGINATION_CLASS, PAGE_SIZE | rest_framework.pagination.PageNumberPagination, 100 as the documented example limit | Current DRF docs | pagination |
pagination_class, page_size | Per-view subclass; page_size = 100 for this example | Current DRF docs | pagination |
page_size_query_param, max_page_size | Default query parameter None means fixed size; if enabled as page_size, cap with max_page_size = 1000 | Current DRF docs; documented example cap | pagination |
Serializer read_only_fields | Include the owner field and use an explicit fields allowlist | Current ModelSerializer API | serializers |
Order of operations
1. Require authentication before reading a private queryset. Filter by owner and choose stable ordering, such as the resource's unique ID. Use that queryset for list and detail; custom actions must retain the same scope (filtering). 2. Implement has_object_permission to require owner equality for every method, including reads. The tutorial's public-read IsOwnerOrReadOnly is unsuitable for private records. The overridden get_object example calls self.check_object_permissions(self.request, obj); omit this only if the API has no object-level permissions (generic views). 3. During create, after serializer validation and before insertion, use perform_create with serializer.save(owner=self.request.user). Ignore a submitted owner through the read-only serializer field, and prevent owner reassignment during update (owner tutorial, serializers). 4. Paginate the already scoped queryset. Generic views/viewsets do this automatically; a plain APIView requires explicit pagination. Compare two users' list counts, detail IDs, create ownership and all pages.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
| Another user's rows appear in list | Object permissions are not run for each list row | Filter get_queryset(); retain object checks for detail and explicit create checks | permissions |
| Related field exposes or accepts another user's object | Relationship fields do not inherit view filtering | Scope writable related-field querysets and validate relationship ownership; restrict nested representation | lovelydinosaur, October 23, 2014, serializers |
The historical relationship report establishes an additional boundary to review; it is not a current release-regression claim.
Missing
- The authentication mechanism and resource/relationship schema are unspecified.
Checked
2026-11-12; current DRF references; 3.16.1 baseline in the release notes (release notes); linked permissions, pagination, filtering, generic views, serializer/tutorial pages and relationship issue read. No Django commands executed.
Started from a post by @Django REST framework, packaged by the editor. Original post