Django REST Framework filtering with django-filter

django-filter provides declarative filtering for DRF viewsets. I define a FilterSet class with fields to filter on. The DjangoFilterBackend integrates seamlessly with DRF. I use CharFilter, NumberFilter, DateFilter etc. for different field types. Look

Django middleware for API versioning

API versioning via middleware provides clean URL routing. I extract version from Accept header or URL prefix and set it on the request object. Views can check request.api_version to return appropriate responses. For breaking changes, I maintain separa

Stimulus: bulk selection + Turbo batch action

For batch operations, Stimulus can manage the UI state (select all, indeterminate checkbox) while Turbo submits a regular form. This keeps the server in charge of authorization and the UI simple.

Django model validation with clean method

The clean() method validates model instances before saving. I raise ValidationError for invalid data. This runs on form submission and can be called explicitly with full_clean(). I validate cross-field constraints that can't be expressed as field vali

Django JSON field for flexible schema data

JSONField stores structured data without creating separate tables. I use it for settings, metadata, or varying attributes. Django provides database-level JSON operations via lookups like __contains, __has_key. For PostgreSQL, I get native JSON operato

Frontend: copy-to-clipboard with fallback

Copying code is a core interaction in a snippets app, and it needs to work reliably across browsers. The modern API is navigator.clipboard.writeText, but it requires HTTPS and permissions in some contexts. I try it first, and if it fails I fall back t

SSE endpoint for server-to-browser events

When I want ‘real time’ updates without the operational overhead of WebSockets, I reach for Server-Sent Events (SSE). It’s just streaming HTTP, so it behaves well behind proxies and is easy to reason about. I set the right headers (Content-Type: text/

Django bulk operations for performance

Bulk operations reduce database round-trips dramatically. I use bulk_create() for inserting many objects at once, bulk_update() for updates, and update() for queryset-level updates. These bypass save() methods and signals for speed. For large datasets

Background Job Backpressure with Queue Depth Guard

When downstream systems degrade, jobs pile up and amplify outages. Add a simple “queue depth guard” so non-critical jobs skip or reschedule instead of making the backlog worse.

Streaming CSV import (Node streams)

The first time a CSV import OOM’d a production process, I stopped trusting ‘just read it into memory’. Now I stream the upload to disk (or S3), stream-parse rows, and batch inserts into the DB. The win is that memory usage stays flat, even when the fi

Inline form validation feedback via Turbo Streams

When forms live inside a Turbo Frame (modal or inline edit), validation needs to feel immediate without a full-page refresh. I render the form inside a frame with an ID like post_form. On submit, create/update returns status: :unprocessable_entity and

Turbo Streams: partial replace with morphing (less jitter)

When replacing DOM chunks, morphing reduces flicker and preserves focus/selection. If you enable morphing, prefer server-rendered HTML that’s stable and keyed. It’s a subtle but meaningful quality improvement.