get or create in django

Solutions on MaxInterview for get or create in django by the best coders in the world

showing results for - "get or create in django"
Nicolás
11 Nov 2019
1try:
2    obj = Person.objects.get(first_name='John', last_name='Lennon')
3except Person.DoesNotExist:
4    obj = Person(first_name='John', last_name='Lennon', birthday=date(1940, 10, 9))
5    obj.save()
6