Skip to content

Instantly share code, notes, and snippets.

@emorozov
emorozov / autofactory.py
Last active June 24, 2025 11:30 — forked from mgaitan/autofactory.py
Automatically define factory boy recipes for dataclasses by inspecting the type annotations
## See https://github.com/FactoryBoy/factory_boy/issues/836
import inspect
from typing import Literal, get_args, get_origin
import factory
import factory.fuzzy
from dataclasses import Field, MISSING, is_dataclass
from enum import Enum
from datetime import date, datetime
def get_auto_field(field: Field):
@emorozov
emorozov / python-django-postgres-ci.yml
Created May 10, 2020 08:08 — forked from jefftriplett/python-django-postgres-ci.yml
This is a good starting point for getting Python, Django, Postgres running as a service, pytest, black, and pip caching rolling with GitHub Actions.
name: CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
services:
"""
Originaly code was taken from: http://djangosnippets.org/snippets/290/
But I was made some improvements like:
- print URL from what queries was
- don't show queries from static URLs (MEDIA_URL and STATIC_URL, also for /favicon.ico).
- If DEBUG is False tell to django to not use this middleware
- Remove guessing of terminal width (This breaks the rendered SQL)
"""
try:
import cProfile as profile
@emorozov
emorozov / list_all_model_signals.py
Last active May 10, 2020 07:51 — forked from runekaagaard/list_all_model_signals.py
List all signals by model and signal type. Tested with Django 3.
# -*- coding: utf-8 -*-
# Based on https://gist.github.com/voldmar/1264102
# and https://gist.github.com/runekaagaard/2eecf0a8367959dc634b7866694daf2c
import gc
import inspect
import weakref
from collections import defaultdict
from django.apps import apps