scripts: start utils module

This commit is contained in:
Benjamin Dauvergne 2013-01-05 21:37:28 +01:00
parent ebddd10a2e
commit 58ebd8fb64
1 changed files with 9 additions and 0 deletions

9
scripts/utils.py Normal file
View File

@ -0,0 +1,9 @@
class QuerysetIndex(object):
'''Create simple index of objects in a queryset'''
def __init__(self, qs, *keywords):
for keyword in keywords:
setattr(self, 'by_' + keyword, dict())
for obj in qs:
for keyword in keywords:
getattr(self, 'by_' + keyword)[getattr(obj, keyword)] = obj