Answers for "get_or_create in django"

1

get_or_create in django

obj, created = Person.objects.get_or_create(
    first_name='John',
    last_name='Lennon',
    defaults={'birthday': date(1940, 10, 9)},
)
Posted by: Guest on May-30-2021
1

get_or_create in django

try:
    obj = Person.objects.get(first_name='John', last_name='Lennon')
except Person.DoesNotExist:
    obj = Person(first_name='John', last_name='Lennon', birthday=date(1940, 10, 9))
    obj.save()
Posted by: Guest on May-30-2021

Python Answers by Framework

Browse Popular Code Answers by Language