Django QuerySet API

 

 

 https://docs.djangoproject.com/en/2.1/ref/models/querysets/

 

update_or_create
update_or_create(defaults=None, **kwargs)
根据kwargs去数据库中查询,其实就是过滤,如果不填,相当于拿所有数据(多个kwargs之间是and的关系)
如果查到:用defaults去更新
查不到:用default和kwargs创建(对于两者间相同的字段,default会覆盖kwargs)

 

    def update_or_create(self, defaults=None, **kwargs):
        """
        Looks up an object with the given kwargs, updating one with defaults
        if it exists, otherwise creates a new one.
        Returns a tuple (object, created), where created is a boolean
        specifying whether an object was created.

 

 

 

 

 

 

 

 

 

 

 

posted @ 2019-02-08 12:14  whitesky-root  阅读(178)  评论(0编辑  收藏  举报