'Does the heavy-lifting involved in saving. Subclasses shouldn\'t need to
override this method. It\'s separate from save() in order to hide the
need for overrides of save() to pass around internal-only parameters
(\'raw\', \'cls\', and \'origin\').'

def save_base(self, raw=False, cls=None, origin=None, force_insert=False, force_update=False, using=None, update_fields=None):

    using = (using or router.db_for_write(self.__class__, instance=self))
    assert (not (force_insert and (force_update or update_fields)))
    assert ((update_fields is None) or (len(update_fields) > 0))
    if (cls is None):
        cls = self.__class__
        meta = cls._meta
        if (not meta.proxy):
            origin = cls
    else:
        meta = cls._meta
    if (origin and (not meta.auto_created)):
        signals.pre_save.send(sender=origin, instance=self, raw=raw, using=using, update_fields=update_fields)
    if ((not raw) or meta.proxy):
        if meta.proxy:
            org = cls
        else:
            org = None
        for (parent, field) in meta.parents.items():
            if (field and (getattr(self, parent._meta.pk.attname) is None) and (getattr(self, field.attname) is not None)):
                setattr(self, parent._meta.pk.attname, getattr(self, field.attname))
            self.save_base(cls=parent, origin=org, using=using, update_fields=update_fields)
            if field:
                setattr(self, field.attname, self._get_pk_val(parent._meta))
                cache_name = field.get_cache_name()
                if hasattr(self, cache_name):
                    delattr(self, cache_name)
        if meta.proxy:
            return
    if (not meta.proxy):
        non_pks = [f for f in meta.local_fields if (not f.primary_key)]
        if update_fields:
            non_pks = [f for f in non_pks if ((f.name in update_fields) or (f.attname in update_fields))]
        pk_val = self._get_pk_val(meta)
        pk_set = (pk_val is not None)
        record_exists = True
        manager = cls._base_manager
        if pk_set:
            if ((force_update or update_fields) or ((not force_insert) and manager.using(using).filter(pk=pk_val).exists())):
                if (force_update or non_pks):
                    values = [(f, None, ((raw and getattr(self, f.attname)) or f.pre_save(self, False))) for f in non_pks]
                    if values:
                        rows = manager.using(using).filter(pk=pk_val)._update(values)
                        if (force_update and (not rows)):
                            raise DatabaseError(u'Forced    update    did    not    affect    any    rows.')
                        if (update_fields and (not rows)):
                            raise DatabaseError(u'Save    with    update_fields    did    not    affect    any    rows.')
            else:
                record_exists = False
        if ((not pk_set) or (not record_exists)):
            if meta.order_with_respect_to:
                field = meta.order_with_respect_to
                order_value = manager.using(using).filter(**{field.name: getattr(self, field.attname)}).count()
                self._order = order_value
            fields = meta.local_fields
            if (not pk_set):
                if (force_update or update_fields):
                    raise ValueError(u'Cannot    force    an    update    in    save()    with    no    primary    key.')
                fields = [f for f in fields if (not isinstance(f, AutoField))]
            record_exists = False
            update_pk = bool((meta.has_auto_field and (not pk_set)))
            result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
            if update_pk:
                setattr(self, meta.pk.attname, result)
        transaction.commit_unless_managed(using=using)
    self._state.db = using
    self._state.adding = False
    if (origin and (not meta.auto_created)):
        signals.post_save.send(sender=origin, instance=self, created=(not record_exists), update_fields=update_fields, raw=raw, using=using)
