

def save(self, force_insert=False, only=None):
    field_dict = dict(self._data)
    if (self._meta.primary_key is not False):
        pk_field = self._meta.primary_key
        pk_value = self._get_pk_value()
    else:
        pk_field = pk_value = None
    if only:
        field_dict = self._prune_fields(field_dict, only)
    elif (self._meta.only_save_dirty and (not force_insert)):
        field_dict = self._prune_fields(field_dict, self.dirty_fields)
        if (not field_dict):
            self._dirty.clear()
            return False
    self._populate_unsaved_relations(field_dict)
    if ((pk_value is not None) and (not force_insert)):
        if self._meta.composite_key:
            for pk_part_name in pk_field.field_names:
                field_dict.pop(pk_part_name, None)
        else:
            field_dict.pop(pk_field.name, None)
        rows = self.update(**field_dict).where(self._pk_expr()).execute()
    elif (pk_field is None):
        self.insert(**field_dict).execute()
        rows = 1
    else:
        pk_from_cursor = self.insert(**field_dict).execute()
        if (pk_from_cursor is not None):
            pk_value = pk_from_cursor
        self._set_pk_value(pk_value)
        rows = 1
    self._dirty.clear()
    return rows

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