Skip to content

Instantly share code, notes, and snippets.

@Sheikh2Imran
Last active December 15, 2019 14:38
Show Gist options
  • Select an option

  • Save Sheikh2Imran/cceaf5d29387b47de64eb2923931507f to your computer and use it in GitHub Desktop.

Select an option

Save Sheikh2Imran/cceaf5d29387b47de64eb2923931507f to your computer and use it in GitHub Desktop.
create_or_get ORM in Django
# should not use
try:
Account.objects.get(username='testuser', password='test1234')
except ObjectDoesNotExist:
Account.objects.create(username='testuser', password='test1234')
# should use
try:
Account.objects.get_or_create(username='testuser', password='test1234')
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment