📜  创建或更新 django 模型 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:57.583000             🧑  作者: Mango

代码示例1
obj, created = Person.objects.update_or_create(
    first_name='John', last_name='Lennon',
    defaults={'first_name': 'Bob'},
)
# If person exists with first_name='John' & last_name='Lennon' then update first_name='Bob'
# Else create new person with first_name='Bob' & last_name='Lennon'