Last active
December 15, 2019 14:38
-
-
Save Sheikh2Imran/cceaf5d29387b47de64eb2923931507f to your computer and use it in GitHub Desktop.
create_or_get ORM in Django
This file contains hidden or 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
| # 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