When should you use only(), defer(), and values()?
Simple meaning
only() loads a subset of columns
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.
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.
Subclass BaseAuthentication and implement authenticate(self, request) returning (user, auth) or None.
Open the full page for Why, Steps, Example and Key takeaway.
to_internal_value runs field-level to_internal_value, then field validators, then validate_<field>, then serializer.validate.
Open the full page for Why, Steps, Example and Key takeaway.
Override create/update and wrap related saves in transaction.atomic().
Open the full page for Why, Steps, Example and Key takeaway.
Hyperlinked identities are nice for HATEOAS clients but couple payloads to URL reversing and request context.
Open the full page for Why, Steps, Example and Key takeaway.
They inspect view serializers, pagination, and authentication to emit OpenAPI.
Open the full page for Why, Steps, Example and Key takeaway.
Workers can crash after running a task but before ack, so the broker redelivers.
Open the full page for Why, Steps, Example and Key takeaway.
Prefetch pulls multiple messages per worker process to hide network latency.
Open the full page for Why, Steps, Example and Key takeaway.