

@classmethod
def create_or_get(cls, **kwargs):
    try:
        with cls._meta.database.atomic():
            return (cls.create(**kwargs), True)
    except IntegrityError:
        query = []
        for (field_name, value) in kwargs.items():
            field = getattr(cls, field_name)
            if (field.unique or field.primary_key):
                query.append((field == value))
        return (cls.get(*query), False)

dataset/ETHPy150Open coleifer/peewee/peewee.py Model.create_or_get/original