create or update django models

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

showing results for - "create or update django models"
Ethan
05 Jul 2017
1obj, created = Person.objects.update_or_create(
2    first_name='John', last_name='Lennon',
3    defaults={'first_name': 'Bob'},
4)
5# If person exists with first_name='John' & last_name='Lennon' then update first_name='Bob'
6# Else create new person with first_name='Bob' & last_name='Lennon'
7