Login

Snippets by andrew

Snippet List

better localsettings import

Most people simply wrap "from localsettings import *" in a try/except ImportError block. That's what I've done for years, but recently came up with this better way. The problem this snippet solves is that if your localsettings.py itself causes an ImportError somehow, that error will be silently swallowed and your intended localsettings will be ignored. Instead, we use `imp` to first check if the module exists, then unconditionally try to import it.

  • development
  • staging
  • production
  • localsettings
Read More

Model dependency graph using graphviz (script)

Instructions: Set your environment variables, install graphviz, and run. Finds all models in your installed apps and makes a handsome graph of your their dependencies based on foreignkey relationships. Django models have green outlines, yours have purple. The edge styling could be changed based on edge type.

  • models
  • graph
  • graphviz
Read More

andrew has posted 6 snippets.