How does a ViewSet differ from GenericAPIView?
Simple meaning
GenericAPIView plus mixins gives you get/post handlers and queryset/serializer_class.
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready Python & Django questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
GenericAPIView plus mixins gives you get/post handlers and queryset/serializer_class.
Open the full page for Why, Steps, Example and Key takeaway.
DefaultRouter and SimpleRouter bind viewset actions to URL patterns including optional trailing slashes.
Open the full page for Why, Steps, Example and Key takeaway.
Authentication identifies the user (who is calling) and sets request.user and request.auth.
Open the full page for Why, Steps, Example and Key takeaway.
Pagination classes split list querysets into pages and add next/previous metadata.
Open the full page for Why, Steps, Example and Key takeaway.
Nest a serializer as a field, or use depth on ModelSerializer for read-only trees.
Open the full page for Why, Steps, Example and Key takeaway.
Enforce access in the view layer (LoginRequiredMixin, permission_required, DRF permissions) so APIs cannot be bypassed.
Open the full page for Why, Steps, Example and Key takeaway.
Unsafe methods need a CSRF token in a header or form field
Open the full page for Why, Steps, Example and Key takeaway.
only() loads a subset of columns
Open the full page for Why, Steps, Example and Key takeaway.
QuerySet caching keeps the whole result in memory after evaluation.
Open the full page for Why, Steps, Example and Key takeaway.
Inside atomic(), select_for_update() takes a row lock so concurrent transactions wait before modifying the same rows.
Open the full page for Why, Steps, Example and Key takeaway.
bulk_create issues INSERT in batches and does not call save() per row, so pre_save/post_save do not run.
Open the full page for Why, Steps, Example and Key takeaway.
Put reusable filters on a custom QuerySet and bind it with as_manager() so you can chain MyModel.objects.published().recent().
Open the full page for Why, Steps, Example and Key takeaway.
annotate() adds per-row annotations and may group by the primary key plus selected fields
Open the full page for Why, Steps, Example and Key takeaway.
Async middleware awaits get_response and must not call blocking ORM without sync_to_async.
Open the full page for Why, Steps, Example and Key takeaway.
StreamingHttpResponse content is an iterator consumed later
Open the full page for Why, Steps, Example and Key takeaway.
AuthenticationMiddleware already sets request.user lazily via SimpleLazyObject.
Open the full page for Why, Steps, Example and Key takeaway.
post_save can fire inside an uncommitted transaction that later rolls back, leaving Celery tasks or emails referring to rows that never existed.
Open the full page for Why, Steps, Example and Key takeaway.
Every save() may fan out to many receivers, including ones in third-party apps you forgot about.
Open the full page for Why, Steps, Example and Key takeaway.
It fires with actions such as pre_add, post_add, pre_remove, and post_clear, and pk_set may be None on clear.
Open the full page for Why, Steps, Example and Key takeaway.
Throttle classes implement allow_request and wait, typically using a cache key of user id or IP plus a rate such as 100/hour.
Open the full page for Why, Steps, Example and Key takeaway.