Last active
June 16, 2016 15:35
-
-
Save wanshot/e2b0571d804a02bf29a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MultiKeyDict(dict): | |
""" | |
>>> format_ = MultiKeyDict({(f.name, f.status): f.id for f in User.objects.all()}) | |
>>> format_.get(u"test") | |
1L | |
>>> format_.get(1) | |
1L | |
""" | |
def __init__(self, *args, **kwargs): | |
for a in args: | |
for k, v in a.items(): | |
if isinstance(k, tuple): | |
self.update({x: v for x in k}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment