Skip to content

Instantly share code, notes, and snippets.

View EBNull's full-sized avatar

EBNull EBNull

  • New York, NY
View GitHub Profile
@EBNull
EBNull / relations.py
Created August 17, 2011 19:21
Returns all foreign key relations to a django model and their accessors
#Some utilities to work with django models and foreign keys.
#Especially useful for finding (and writing out) code to illuminate information about relations.
#
#To try it out, run show_relation_accessors(model) in a python prompt, or to be more general, get_related_instance_ids_code(model)
#
#-2011 CBWhiz
#
#
#Usage sample:
# from django.db import transaction
@EBNull
EBNull / stickyrouter.py
Created March 25, 2011 18:08
Lets django find certain models on a certain database. Cross DB joins will still probably fail.
from django.conf import settings
#STICKY_DB_DEFAULT=None
#STICKY_DB_ALLOW_CROSS_DB_RELATIONS=False
#STICKY_DB_MODELS = {
# ('app', 'model'): 'dbalias',
# ('app', 'model'): 'dbalias',
# ('app', 'model'): 'dbalias',
#}
@EBNull
EBNull / install_winprint_hylafax_7.py
Created March 15, 2011 16:37
Install script for https://sourceforge.net/projects/wphfforwin7 . Installs files, port monitor, port, driver, and printer.
#Run this script to install system files, port monitor, port, driver, and printer
#You can change settings in the main() function
#
#(c) 2011 CBWhiz
import os
import sys
import ctypes
import subprocess
import codecs
import tempfile
@EBNull
EBNull / globalinteract-withdjango.py
Created February 10, 2011 19:59
Version of Python's code.interact() that takes a `globals` argument
import code, sys
from code import softspace
class GlobalInteractiveConsole(code.InteractiveConsole):
"""Interactive console that also takes a globals argument"""
def __init__(self, locals=None, filename="<console>", globals=None):
try:
super(GlobalInteractiveConsole, self).__init__(locals=locals, filename=filename)
except TypeError:
code.InteractiveConsole.__init__(self, locals=locals, filename=filename)
if globals is None: