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

查看:456
本文介绍了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天全站免登陆