Skip to content

Instantly share code, notes, and snippets.

View geoffrey-eisenbarth's full-sized avatar

Geoffrey B. Eisenbarth geoffrey-eisenbarth

View GitHub Profile
@geoffrey-eisenbarth
geoffrey-eisenbarth / fields.py
Created April 15, 2026 12:23
A Grouped ModelChoice Field for Django
from itertools import groupby
from typing import TYPE_CHECKING, TypeVar, Generic, cast
from django.forms.fields import ChoiceField
from django.forms.models import (
ModelChoiceIterator, ModelChoiceField, ModelMultipleChoiceField,
)
@geoffrey-eisenbarth
geoffrey-eisenbarth / linked_scroll.html
Last active April 11, 2026 13:05
Hyperscript Demo: Linked Scroll
<style>
main {
display: grid;
gap: 1em;
grid-template-columns: 1fr 1fr;
}
.column {
max-block-size: 200px;
overflow: auto;
border: 2px inset plum;
@geoffrey-eisenbarth
geoffrey-eisenbarth / middleware.py
Last active May 22, 2025 16:04
HttpVerbViewMiddleware for Django+HTMX
from django.http import HttpRequest, HttpResponse, QueryDict
class HttpVerbViewMiddleware:
"""Adds support for all HTTP verbs.
Notes
-----
Django uses request.GET and request.POST to store QueryDicts
of the request's URL parameters and body respectively. In an
@geoffrey-eisenbarth
geoffrey-eisenbarth / forms.py
Last active January 5, 2025 16:56
Django Form Attributes Mixin
from django.utils.translation import gettext_lazy as _
class FormMixin:
"""Adds extra classes and attributes to HTML widgets."""
# This value will change with your CSS framework.
# https://missing.style/
error_css_class = 'bad color'
@geoffrey-eisenbarth
geoffrey-eisenbarth / middleware.py
Last active September 11, 2024 19:44
Django Middleware for django-template-partials
class HtmxPartialTemplateMiddleware:
"""Adds support for rendering partials with django-template-partials.
NOTES
-----
In order for this middleware to work properly, the following conditions must be met:
1) django-template-partials must be installed
2) Each template must have a partial defined directly in it with a name that coincides
with the HTML id of the element being swapped out. Since django-template-partials does