Skip to content

Instantly share code, notes, and snippets.

@kipanshi
Created December 26, 2011 08:13
Show Gist options
  • Save kipanshi/1520747 to your computer and use it in GitHub Desktop.
Save kipanshi/1520747 to your computer and use it in GitHub Desktop.
Acessing global namespace
# Assume you have model ``Project`` with 1:M relation to ``Task``
# here ``p`` instance of ``Project``, and it has some amount of tasks
# Following inline is creating global variable ``t<idx>`` for each task (e.g. t1, t2, ...)
[globals().update({'t%s' % (idx + 1): t}) for idx, t in enumerate(p.tasks.all())]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment