get or create in django

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

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
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