Django 模型方法 - create_or_update [英] Django model method - create_or_update

查看:27
本文介绍了Django 模型方法 - create_or_update的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于get_or_create,我希望能够在 Django 中update_or_create.

到目前为止,我使用的方法类似于 @Daniel Roseman 在这里.但是,作为模型方法,我想更简洁地做到这一点.

Until now, I have using an approaching similar to how @Daniel Roseman does it here. However, I'd like to do this more succinctly as a model method.

这个片段很旧,我想知道是否有更好的方法来做到这一点更新版本的 Django.

This snippet is quite old and I was wondering if there is a better way to do this in more recent version of Django.

推荐答案

参见 QuerySet.update_or_create(Django 1.7dev 中的新功能)

See QuerySet.update_or_create (new in Django 1.7dev)

这篇关于Django 模型方法 - create_or_update的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆