Skip to content

Instantly share code, notes, and snippets.

@ninapavlich
ninapavlich / admin.py
Created December 21, 2017 02:24
Cache foreign key lookups in django admin line forms
class CachedChoiceFieldOptionsMixin(object):
"""
This class speeds up performance of inline foreign-key pickers so we don't have to re-query the options for each item in the list
"""
cached_choice_fields = []
def formfield_for_dbfield(self, db_field, **kwargs):
request = kwargs['request']
formfield = super(CachedChoiceFieldOptionsMixin,
@ipmb
ipmb / settings.py
Last active November 11, 2024 07:14
Django logging example
import logging.config
import os
from django.utils.log import DEFAULT_LOGGING
# Disable Django's logging setup
LOGGING_CONFIG = None
LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper()
logging.config.dictConfig({
@m14t
m14t / fix_github_https_repo.sh
Created July 5, 2012 21:57
Convert HTTPS github clones to use SSH
#/bin/bash
#-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password
REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(https://[^[:space:]]*).*#\1#p'`
if [ -z "$REPO_URL" ]; then
echo "-- ERROR: Could not identify Repo url."
echo " It is possible this repo is already using SSH instead of HTTPS."
exit
fi
anonymous
anonymous / 2
Created September 18, 2011 18:28
run:
Display name: em1
Name: em1
InetAddress: /192.168.1.103
Display name: lo
Name: lo
InetAddress: /127.0.0.1
BUILD SUCCESSFUL (total time: 0 seconds)