def update_or_create(self, defaults=None, **kwargs):
        defaults = defaults or {}
        lookup, params = self._extract_model_params(defaults, **kwargs)
        self._for_write = True
        try:
            obj = self.get(**lookup)
        except self.model.DoesNotExist:
            obj, created = self._create_object_from_params(lookup, params)
            if created:
                return obj, created
        for k, v in six.iteritems(defaults):
            setattr(obj, k, v)
        obj.save(using=self.db)
        return obj, False
Looks up an object with the given kwargs, updating one with defaults
dataset/ETHPy150Open django/django/django/db/models/query.py/QuerySet.update_or_create