def get_or_create(self, defaults=None, **kwargs):
        lookup, params = self._extract_model_params(defaults, **kwargs)
        # The get() needs to be targeted at the write database in order
        # to avoid potential transaction consistency problems.
        self._for_write = True
        try:
            return self.get(**lookup), False
        except self.model.DoesNotExist:
            return self._create_object_from_params(lookup, params)
Looks up an object with the given kwargs, creating one if necessary.
dataset/ETHPy150Open django/django/django/db/models/query.py/QuerySet.get_or_create