Created
January 28, 2013 23:13
-
-
Save EyePulp/4660178 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
def get_or_none(model, *args, **kwargs): | |
""" | |
look for a model instance, return None if it doesn't exists | |
""" | |
try: | |
return model.objects.get(*args,**kwargs) | |
except model.DoesNotExist: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment