How to update fields in a model without creating a new record in django?

后端 未结 5 1673
你的背包
你的背包 2020-12-23 11:14

I have a model in django that I want to update only, that is, when I call it and set the data, it will not create a new record, only update the existing one. How can I do th

5条回答
  •  盖世英雄少女心
    2020-12-23 11:42

    You should do it this way ideally

    t = TemperatureData.objects.get(id=1)
    t.value = 999
    t.save(['value'])
    

    This allow you to specify which column should be saved and rest are left as they currently are in database. (https://code.djangoproject.com/ticket/4102)!

提交回复
热议问题