Skip to content

Instantly share code, notes, and snippets.

@EyePulp
Created January 28, 2013 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EyePulp/4660178 to your computer and use it in GitHub Desktop.
Save EyePulp/4660178 to your computer and use it in GitHub Desktop.
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