Skip to content

Instantly share code, notes, and snippets.

View vdboor's full-sized avatar

Diederik van der Boor vdboor

View GitHub Profile
@vdboor
vdboor / sqlmigrate_custom.py
Last active December 15, 2022 14:18
Running the Django migration engine for custom models
from django.core.management import BaseCommand
from django.db import connection, models
from django.db.migrations import Migration
from django.db.migrations.autodetector import MigrationAutodetector
from django.db.migrations.graph import MigrationGraph
from django.db.migrations.questioner import InteractiveMigrationQuestioner
from django.db.migrations.state import ModelState, ProjectState
class PatchedModelState(ModelState):
@vdboor
vdboor / caching.py
Created January 4, 2023 14:14
A @cache_results decorator for functions that gives full control over bypassing/refreshing/clearing the cache
import functools
import logging
from django.core.cache import DEFAULT_CACHE_ALIAS, caches
logger = logging.getLogger(__name__)
class CachedFunction:
"""
The CachedFunction is a proxy object that implements cache-wrapper logic around