package models

import (
	"bytes"
	"database/sql"
	"fmt"
	"reflect"
	"strings"
	"sync"
	"time"

	"github.com/pkg/errors"
	"github.com/vattle/sqlboiler/boil"
	"github.com/vattle/sqlboiler/queries"
	"github.com/vattle/sqlboiler/queries/qm"
	"github.com/vattle/sqlboiler/strmangle"
	"gopkg.in/nullbio/null.v6"
)

type DjangoAdminLog struct {
	ID            int         `boil:"id" json:"id" toml:"id" yaml:"id"`
	ActionTime    time.Time   `boil:"action_time" json:"action_time" toml:"action_time" yaml:"action_time"`
	UserID        int         `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"`
	ContentTypeID null.Int    `boil:"content_type_id" json:"content_type_id,omitempty" toml:"content_type_id" yaml:"content_type_id,omitempty"`
	ObjectID      null.String `boil:"object_id" json:"object_id,omitempty" toml:"object_id" yaml:"object_id,omitempty"`
	ObjectRepr    string      `boil:"object_repr" json:"object_repr" toml:"object_repr" yaml:"object_repr"`
	ActionFlag    int16       `boil:"action_flag" json:"action_flag" toml:"action_flag" yaml:"action_flag"`
	ChangeMessage string      `boil:"change_message" json:"change_message" toml:"change_message" yaml:"change_message"`

	R *djangoAdminLogR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L djangoAdminLogL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

type djangoAdminLogR struct {
	ContentType *DjangoContentType
	User        *AuthUser
}

type djangoAdminLogL struct{}

var (
	djangoAdminLogColumns               = []string{"id", "action_time", "user_id", "content_type_id", "object_id", "object_repr", "action_flag", "change_message"}
	djangoAdminLogColumnsWithoutDefault = []string{"action_time", "user_id", "content_type_id", "object_id", "object_repr", "action_flag", "change_message"}
	djangoAdminLogColumnsWithDefault    = []string{"id"}
	djangoAdminLogPrimaryKeyColumns     = []string{"id"}
)

type (

	DjangoAdminLogSlice []*DjangoAdminLog

	djangoAdminLogQuery struct {
		*queries.Query
	}
)

var (
	djangoAdminLogType                 = reflect.TypeOf(&DjangoAdminLog{})
	djangoAdminLogMapping              = queries.MakeStructMapping(djangoAdminLogType)
	djangoAdminLogPrimaryKeyMapping, _ = queries.BindMapping(djangoAdminLogType, djangoAdminLogMapping, djangoAdminLogPrimaryKeyColumns)
	djangoAdminLogInsertCacheMut       sync.RWMutex
	djangoAdminLogInsertCache          = make(map[string]insertCache)
	djangoAdminLogUpdateCacheMut       sync.RWMutex
	djangoAdminLogUpdateCache          = make(map[string]updateCache)
	djangoAdminLogUpsertCacheMut       sync.RWMutex
	djangoAdminLogUpsertCache          = make(map[string]insertCache)
)

var (

	_ = time.Second

	_ = bytes.MinRead
)

func (q djangoAdminLogQuery) OneP() *DjangoAdminLog {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return o
}

func (q djangoAdminLogQuery) One() (*DjangoAdminLog, error) {
	o := &DjangoAdminLog{}

	queries.SetLimit(q.Query, 1)

	err := q.Bind(o)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "models: failed to execute a one query for django_admin_log")
	}

	return o, nil
}

func (q djangoAdminLogQuery) AllP() DjangoAdminLogSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return o
}

func (q djangoAdminLogQuery) All() (DjangoAdminLogSlice, error) {
	var o DjangoAdminLogSlice

	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "models: failed to assign all query results to DjangoAdminLog slice")
	}

	return o, nil
}

func (q djangoAdminLogQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return c
}

func (q djangoAdminLogQuery) Count() (int64, error) {
	var count int64

	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)

	err := q.Query.QueryRow().Scan(&count)
	if err != nil {
		return 0, errors.Wrap(err, "models: failed to count django_admin_log rows")
	}

	return count, nil
}

func (q djangoAdminLogQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return e
}

func (q djangoAdminLogQuery) Exists() (bool, error) {
	var count int64

	queries.SetCount(q.Query)
	queries.SetLimit(q.Query, 1)

	err := q.Query.QueryRow().Scan(&count)
	if err != nil {
		return false, errors.Wrap(err, "models: failed to check if django_admin_log exists")
	}

	return count > 0, nil
}

func (o *DjangoAdminLog) ContentTypeG(mods ...qm.QueryMod) djangoContentTypeQuery {
	return o.ContentType(boil.GetDB(), mods...)
}

func (o *DjangoAdminLog) ContentType(exec boil.Executor, mods ...qm.QueryMod) djangoContentTypeQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.ContentTypeID),
	}

	queryMods = append(queryMods, mods...)

	query := DjangoContentTypes(exec, queryMods...)
	queries.SetFrom(query.Query, "`django_content_type`")

	return query
}

func (o *DjangoAdminLog) UserG(mods ...qm.QueryMod) authUserQuery {
	return o.User(boil.GetDB(), mods...)
}

func (o *DjangoAdminLog) User(exec boil.Executor, mods ...qm.QueryMod) authUserQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.UserID),
	}

	queryMods = append(queryMods, mods...)

	query := AuthUsers(exec, queryMods...)
	queries.SetFrom(query.Query, "`auth_user`")

	return query
}

func (djangoAdminLogL) LoadContentType(e boil.Executor, singular bool, maybeDjangoAdminLog interface{}) error {
	var slice []*DjangoAdminLog
	var object *DjangoAdminLog

	count := 1
	if singular {
		object = maybeDjangoAdminLog.(*DjangoAdminLog)
	} else {
		slice = *maybeDjangoAdminLog.(*DjangoAdminLogSlice)
		count = len(slice)
	}

	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &djangoAdminLogR{}
		}
		args[0] = object.ContentTypeID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &djangoAdminLogR{}
			}
			args[i] = obj.ContentTypeID
		}
	}

	query := fmt.Sprintf(
		"select * from `django_content_type` where `id` in (%s)",
		strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
	)

	if boil.DebugMode {
		fmt.Fprintf(boil.DebugWriter, "%s\n%v\n", query, args)
	}

	results, err := e.Query(query, args...)
	if err != nil {
		return errors.Wrap(err, "failed to eager load DjangoContentType")
	}
	defer results.Close()

	var resultSlice []*DjangoContentType
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice DjangoContentType")
	}

	if len(resultSlice) == 0 {
		return nil
	}

	if singular {
		object.R.ContentType = resultSlice[0]
		return nil
	}

	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.ContentTypeID.Int == foreign.ID {
				local.R.ContentType = foreign
				break
			}
		}
	}

	return nil
}

func (djangoAdminLogL) LoadUser(e boil.Executor, singular bool, maybeDjangoAdminLog interface{}) error {
	var slice []*DjangoAdminLog
	var object *DjangoAdminLog

	count := 1
	if singular {
		object = maybeDjangoAdminLog.(*DjangoAdminLog)
	} else {
		slice = *maybeDjangoAdminLog.(*DjangoAdminLogSlice)
		count = len(slice)
	}

	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &djangoAdminLogR{}
		}
		args[0] = object.UserID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &djangoAdminLogR{}
			}
			args[i] = obj.UserID
		}
	}

	query := fmt.Sprintf(
		"select * from `auth_user` where `id` in (%s)",
		strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
	)

	if boil.DebugMode {
		fmt.Fprintf(boil.DebugWriter, "%s\n%v\n", query, args)
	}

	results, err := e.Query(query, args...)
	if err != nil {
		return errors.Wrap(err, "failed to eager load AuthUser")
	}
	defer results.Close()

	var resultSlice []*AuthUser
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice AuthUser")
	}

	if len(resultSlice) == 0 {
		return nil
	}

	if singular {
		object.R.User = resultSlice[0]
		return nil
	}

	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.UserID == foreign.ID {
				local.R.User = foreign
				break
			}
		}
	}

	return nil
}

func (o *DjangoAdminLog) SetContentTypeG(insert bool, related *DjangoContentType) error {
	return o.SetContentType(boil.GetDB(), insert, related)
}

func (o *DjangoAdminLog) SetContentTypeP(exec boil.Executor, insert bool, related *DjangoContentType) {
	if err := o.SetContentType(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) SetContentTypeGP(insert bool, related *DjangoContentType) {
	if err := o.SetContentType(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) SetContentType(exec boil.Executor, insert bool, related *DjangoContentType) error {
	var err error
	if insert {
		if err = related.Insert(exec); err != nil {
			return errors.Wrap(err, "failed to insert into foreign table")
		}
	}

	updateQuery := fmt.Sprintf(
		"UPDATE `django_admin_log` SET %s WHERE %s",
		strmangle.SetParamNames("`", "`", 0, []string{"content_type_id"}),
		strmangle.WhereClause("`", "`", 0, djangoAdminLogPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.ID}

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, updateQuery)
		fmt.Fprintln(boil.DebugWriter, values)
	}

	if _, err = exec.Exec(updateQuery, values...); err != nil {
		return errors.Wrap(err, "failed to update local table")
	}

	o.ContentTypeID.Int = related.ID
	o.ContentTypeID.Valid = true

	if o.R == nil {
		o.R = &djangoAdminLogR{
			ContentType: related,
		}
	} else {
		o.R.ContentType = related
	}

	if related.R == nil {
		related.R = &djangoContentTypeR{
			ContentTypeDjangoAdminLogs: DjangoAdminLogSlice{o},
		}
	} else {
		related.R.ContentTypeDjangoAdminLogs = append(related.R.ContentTypeDjangoAdminLogs, o)
	}

	return nil
}

func (o *DjangoAdminLog) RemoveContentTypeG(related *DjangoContentType) error {
	return o.RemoveContentType(boil.GetDB(), related)
}

func (o *DjangoAdminLog) RemoveContentTypeP(exec boil.Executor, related *DjangoContentType) {
	if err := o.RemoveContentType(exec, related); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) RemoveContentTypeGP(related *DjangoContentType) {
	if err := o.RemoveContentType(boil.GetDB(), related); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) RemoveContentType(exec boil.Executor, related *DjangoContentType) error {
	var err error

	o.ContentTypeID.Valid = false
	if err = o.Update(exec, "content_type_id"); err != nil {
		o.ContentTypeID.Valid = true
		return errors.Wrap(err, "failed to update local table")
	}

	o.R.ContentType = nil
	if related == nil || related.R == nil {
		return nil
	}

	for i, ri := range related.R.ContentTypeDjangoAdminLogs {
		if o.ContentTypeID.Int != ri.ContentTypeID.Int {
			continue
		}

		ln := len(related.R.ContentTypeDjangoAdminLogs)
		if ln > 1 && i < ln-1 {
			related.R.ContentTypeDjangoAdminLogs[i] = related.R.ContentTypeDjangoAdminLogs[ln-1]
		}
		related.R.ContentTypeDjangoAdminLogs = related.R.ContentTypeDjangoAdminLogs[:ln-1]
		break
	}
	return nil
}

func (o *DjangoAdminLog) SetUserG(insert bool, related *AuthUser) error {
	return o.SetUser(boil.GetDB(), insert, related)
}

func (o *DjangoAdminLog) SetUserP(exec boil.Executor, insert bool, related *AuthUser) {
	if err := o.SetUser(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) SetUserGP(insert bool, related *AuthUser) {
	if err := o.SetUser(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) SetUser(exec boil.Executor, insert bool, related *AuthUser) error {
	var err error
	if insert {
		if err = related.Insert(exec); err != nil {
			return errors.Wrap(err, "failed to insert into foreign table")
		}
	}

	updateQuery := fmt.Sprintf(
		"UPDATE `django_admin_log` SET %s WHERE %s",
		strmangle.SetParamNames("`", "`", 0, []string{"user_id"}),
		strmangle.WhereClause("`", "`", 0, djangoAdminLogPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.ID}

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, updateQuery)
		fmt.Fprintln(boil.DebugWriter, values)
	}

	if _, err = exec.Exec(updateQuery, values...); err != nil {
		return errors.Wrap(err, "failed to update local table")
	}

	o.UserID = related.ID

	if o.R == nil {
		o.R = &djangoAdminLogR{
			User: related,
		}
	} else {
		o.R.User = related
	}

	if related.R == nil {
		related.R = &authUserR{
			UserDjangoAdminLogs: DjangoAdminLogSlice{o},
		}
	} else {
		related.R.UserDjangoAdminLogs = append(related.R.UserDjangoAdminLogs, o)
	}

	return nil
}

func DjangoAdminLogsG(mods ...qm.QueryMod) djangoAdminLogQuery {
	return DjangoAdminLogs(boil.GetDB(), mods...)
}

func DjangoAdminLogs(exec boil.Executor, mods ...qm.QueryMod) djangoAdminLogQuery {
	mods = append(mods, qm.From("`django_admin_log`"))
	return djangoAdminLogQuery{NewQuery(exec, mods...)}
}

func FindDjangoAdminLogG(id int, selectCols ...string) (*DjangoAdminLog, error) {
	return FindDjangoAdminLog(boil.GetDB(), id, selectCols...)
}

func FindDjangoAdminLogGP(id int, selectCols ...string) *DjangoAdminLog {
	retobj, err := FindDjangoAdminLog(boil.GetDB(), id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return retobj
}

func FindDjangoAdminLog(exec boil.Executor, id int, selectCols ...string) (*DjangoAdminLog, error) {
	djangoAdminLogObj := &DjangoAdminLog{}

	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from `django_admin_log` where `id`=?", sel,
	)

	q := queries.Raw(exec, query, id)

	err := q.Bind(djangoAdminLogObj)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "models: unable to select from django_admin_log")
	}

	return djangoAdminLogObj, nil
}

func FindDjangoAdminLogP(exec boil.Executor, id int, selectCols ...string) *DjangoAdminLog {
	retobj, err := FindDjangoAdminLog(exec, id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return retobj
}

func (o *DjangoAdminLog) InsertG(whitelist ...string) error {
	return o.Insert(boil.GetDB(), whitelist...)
}

func (o *DjangoAdminLog) InsertGP(whitelist ...string) {
	if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) InsertP(exec boil.Executor, whitelist ...string) {
	if err := o.Insert(exec, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) Insert(exec boil.Executor, whitelist ...string) error {
	if o == nil {
		return errors.New("models: no django_admin_log provided for insertion")
	}

	var err error

	nzDefaults := queries.NonZeroDefaultSet(djangoAdminLogColumnsWithDefault, o)

	key := makeCacheKey(whitelist, nzDefaults)
	djangoAdminLogInsertCacheMut.RLock()
	cache, cached := djangoAdminLogInsertCache[key]
	djangoAdminLogInsertCacheMut.RUnlock()

	if !cached {
		wl, returnColumns := strmangle.InsertColumnSet(
			djangoAdminLogColumns,
			djangoAdminLogColumnsWithDefault,
			djangoAdminLogColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)

		cache.valueMapping, err = queries.BindMapping(djangoAdminLogType, djangoAdminLogMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(djangoAdminLogType, djangoAdminLogMapping, returnColumns)
		if err != nil {
			return err
		}
		cache.query = fmt.Sprintf("INSERT INTO `django_admin_log` (`%s`) VALUES (%s)", strings.Join(wl, "`,`"), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))

		if len(cache.retMapping) != 0 {
			cache.retQuery = fmt.Sprintf("SELECT `%s` FROM `django_admin_log` WHERE %s", strings.Join(returnColumns, "`,`"), strmangle.WhereClause("`", "`", 0, djangoAdminLogPrimaryKeyColumns))
		}
	}

	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, vals)
	}

	result, err := exec.Exec(cache.query, vals...)

	if err != nil {
		return errors.Wrap(err, "models: unable to insert into django_admin_log")
	}

	var lastID int64
	var identifierCols []interface{}

	if len(cache.retMapping) == 0 {
		goto CacheNoHooks
	}

	lastID, err = result.LastInsertId()
	if err != nil {
		return ErrSyncFail
	}

	o.ID = int(lastID)
	if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == djangoAdminLogMapping["ID"] {
		goto CacheNoHooks
	}

	identifierCols = []interface{}{
		o.ID,
	}

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.retQuery)
		fmt.Fprintln(boil.DebugWriter, identifierCols...)
	}

	err = exec.QueryRow(cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
	if err != nil {
		return errors.Wrap(err, "models: unable to populate default values for django_admin_log")
	}

CacheNoHooks:
	if !cached {
		djangoAdminLogInsertCacheMut.Lock()
		djangoAdminLogInsertCache[key] = cache
		djangoAdminLogInsertCacheMut.Unlock()
	}

	return nil
}

func (o *DjangoAdminLog) UpdateG(whitelist ...string) error {
	return o.Update(boil.GetDB(), whitelist...)
}

func (o *DjangoAdminLog) UpdateGP(whitelist ...string) {
	if err := o.Update(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) UpdateP(exec boil.Executor, whitelist ...string) {
	err := o.Update(exec, whitelist...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) Update(exec boil.Executor, whitelist ...string) error {
	var err error
	key := makeCacheKey(whitelist, nil)
	djangoAdminLogUpdateCacheMut.RLock()
	cache, cached := djangoAdminLogUpdateCache[key]
	djangoAdminLogUpdateCacheMut.RUnlock()

	if !cached {
		wl := strmangle.UpdateColumnSet(djangoAdminLogColumns, djangoAdminLogPrimaryKeyColumns, whitelist)
		if len(wl) == 0 {
			return errors.New("models: unable to update django_admin_log, could not build whitelist")
		}

		cache.query = fmt.Sprintf("UPDATE `django_admin_log` SET %s WHERE %s",
			strmangle.SetParamNames("`", "`", 0, wl),
			strmangle.WhereClause("`", "`", 0, djangoAdminLogPrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(djangoAdminLogType, djangoAdminLogMapping, append(wl, djangoAdminLogPrimaryKeyColumns...))
		if err != nil {
			return err
		}
	}

	values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, values)
	}

	_, err = exec.Exec(cache.query, values...)
	if err != nil {
		return errors.Wrap(err, "models: unable to update django_admin_log row")
	}

	if !cached {
		djangoAdminLogUpdateCacheMut.Lock()
		djangoAdminLogUpdateCache[key] = cache
		djangoAdminLogUpdateCacheMut.Unlock()
	}

	return nil
}

func (q djangoAdminLogQuery) UpdateAllP(cols M) {
	if err := q.UpdateAll(cols); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (q djangoAdminLogQuery) UpdateAll(cols M) error {
	queries.SetUpdate(q.Query, cols)

	_, err := q.Query.Exec()
	if err != nil {
		return errors.Wrap(err, "models: unable to update all for django_admin_log")
	}

	return nil
}

func (o DjangoAdminLogSlice) UpdateAllG(cols M) error {
	return o.UpdateAll(boil.GetDB(), cols)
}

func (o DjangoAdminLogSlice) UpdateAllGP(cols M) {
	if err := o.UpdateAll(boil.GetDB(), cols); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o DjangoAdminLogSlice) UpdateAllP(exec boil.Executor, cols M) {
	if err := o.UpdateAll(exec, cols); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o DjangoAdminLogSlice) UpdateAll(exec boil.Executor, cols M) error {
	ln := int64(len(o))
	if ln == 0 {
		return nil
	}

	if len(cols) == 0 {
		return errors.New("models: update all requires at least one column argument")
	}

	colNames := make([]string, len(cols))
	args := make([]interface{}, len(cols))

	i := 0
	for name, value := range cols {
		colNames[i] = name
		args[i] = value
		i++
	}

	for _, obj := range o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), djangoAdminLogPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := fmt.Sprintf(
		"UPDATE `django_admin_log` SET %s WHERE (`id`) IN (%s)",
		strmangle.SetParamNames("`", "`", 0, colNames),
		strmangle.Placeholders(dialect.IndexPlaceholders, len(o)*len(djangoAdminLogPrimaryKeyColumns), len(colNames)+1, len(djangoAdminLogPrimaryKeyColumns)),
	)

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, sql)
		fmt.Fprintln(boil.DebugWriter, args...)
	}

	_, err := exec.Exec(sql, args...)
	if err != nil {
		return errors.Wrap(err, "models: unable to update all in djangoAdminLog slice")
	}

	return nil
}

func (o *DjangoAdminLog) UpsertG(updateColumns []string, whitelist ...string) error {
	return o.Upsert(boil.GetDB(), updateColumns, whitelist...)
}

func (o *DjangoAdminLog) UpsertGP(updateColumns []string, whitelist ...string) {
	if err := o.Upsert(boil.GetDB(), updateColumns, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) UpsertP(exec boil.Executor, updateColumns []string, whitelist ...string) {
	if err := o.Upsert(exec, updateColumns, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) Upsert(exec boil.Executor, updateColumns []string, whitelist ...string) error {
	if o == nil {
		return errors.New("models: no django_admin_log provided for upsert")
	}

	nzDefaults := queries.NonZeroDefaultSet(djangoAdminLogColumnsWithDefault, o)

	buf := strmangle.GetBuffer()
	for _, c := range updateColumns {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	for _, c := range whitelist {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	for _, c := range nzDefaults {
		buf.WriteString(c)
	}
	key := buf.String()
	strmangle.PutBuffer(buf)

	djangoAdminLogUpsertCacheMut.RLock()
	cache, cached := djangoAdminLogUpsertCache[key]
	djangoAdminLogUpsertCacheMut.RUnlock()

	var err error

	if !cached {
		var ret []string
		whitelist, ret = strmangle.InsertColumnSet(
			djangoAdminLogColumns,
			djangoAdminLogColumnsWithDefault,
			djangoAdminLogColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)
		update := strmangle.UpdateColumnSet(
			djangoAdminLogColumns,
			djangoAdminLogPrimaryKeyColumns,
			updateColumns,
		)
		if len(update) == 0 {
			return errors.New("models: unable to upsert django_admin_log, could not build update column list")
		}

		cache.query = queries.BuildUpsertQueryMySQL(dialect, "django_admin_log", update, whitelist)
		cache.retQuery = fmt.Sprintf(
			"SELECT %s FROM `django_admin_log` WHERE `id`=?",
			strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, ret), ","),
		)

		cache.valueMapping, err = queries.BindMapping(djangoAdminLogType, djangoAdminLogMapping, whitelist)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(djangoAdminLogType, djangoAdminLogMapping, ret)
			if err != nil {
				return err
			}
		}
	}

	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)
	var returns []interface{}
	if len(cache.retMapping) != 0 {
		returns = queries.PtrsFromMapping(value, cache.retMapping)
	}

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, vals)
	}

	result, err := exec.Exec(cache.query, vals...)

	if err != nil {
		return errors.Wrap(err, "models: unable to upsert for django_admin_log")
	}

	var lastID int64
	var identifierCols []interface{}

	if len(cache.retMapping) == 0 {
		goto CacheNoHooks
	}

	lastID, err = result.LastInsertId()
	if err != nil {
		return ErrSyncFail
	}

	o.ID = int(lastID)
	if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == djangoAdminLogMapping["ID"] {
		goto CacheNoHooks
	}

	identifierCols = []interface{}{
		o.ID,
	}

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.retQuery)
		fmt.Fprintln(boil.DebugWriter, identifierCols...)
	}

	err = exec.QueryRow(cache.retQuery, identifierCols...).Scan(returns...)
	if err != nil {
		return errors.Wrap(err, "models: unable to populate default values for django_admin_log")
	}

CacheNoHooks:
	if !cached {
		djangoAdminLogUpsertCacheMut.Lock()
		djangoAdminLogUpsertCache[key] = cache
		djangoAdminLogUpsertCacheMut.Unlock()
	}

	return nil
}

func (o *DjangoAdminLog) DeleteP(exec boil.Executor) {
	if err := o.Delete(exec); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) DeleteG() error {
	if o == nil {
		return errors.New("models: no DjangoAdminLog provided for deletion")
	}

	return o.Delete(boil.GetDB())
}

func (o *DjangoAdminLog) DeleteGP() {
	if err := o.DeleteG(); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) Delete(exec boil.Executor) error {
	if o == nil {
		return errors.New("models: no DjangoAdminLog provided for delete")
	}

	args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), djangoAdminLogPrimaryKeyMapping)
	sql := "DELETE FROM `django_admin_log` WHERE `id`=?"

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, sql)
		fmt.Fprintln(boil.DebugWriter, args...)
	}

	_, err := exec.Exec(sql, args...)
	if err != nil {
		return errors.Wrap(err, "models: unable to delete from django_admin_log")
	}

	return nil
}

func (q djangoAdminLogQuery) DeleteAllP() {
	if err := q.DeleteAll(); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (q djangoAdminLogQuery) DeleteAll() error {
	if q.Query == nil {
		return errors.New("models: no djangoAdminLogQuery provided for delete all")
	}

	queries.SetDelete(q.Query)

	_, err := q.Query.Exec()
	if err != nil {
		return errors.Wrap(err, "models: unable to delete all from django_admin_log")
	}

	return nil
}

func (o DjangoAdminLogSlice) DeleteAllGP() {
	if err := o.DeleteAllG(); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o DjangoAdminLogSlice) DeleteAllG() error {
	if o == nil {
		return errors.New("models: no DjangoAdminLog slice provided for delete all")
	}
	return o.DeleteAll(boil.GetDB())
}

func (o DjangoAdminLogSlice) DeleteAllP(exec boil.Executor) {
	if err := o.DeleteAll(exec); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o DjangoAdminLogSlice) DeleteAll(exec boil.Executor) error {
	if o == nil {
		return errors.New("models: no DjangoAdminLog slice provided for delete all")
	}

	if len(o) == 0 {
		return nil
	}

	var args []interface{}
	for _, obj := range o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), djangoAdminLogPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := fmt.Sprintf(
		"DELETE FROM `django_admin_log` WHERE (%s) IN (%s)",
		strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, djangoAdminLogPrimaryKeyColumns), ","),
		strmangle.Placeholders(dialect.IndexPlaceholders, len(o)*len(djangoAdminLogPrimaryKeyColumns), 1, len(djangoAdminLogPrimaryKeyColumns)),
	)

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, sql)
		fmt.Fprintln(boil.DebugWriter, args)
	}

	_, err := exec.Exec(sql, args...)
	if err != nil {
		return errors.Wrap(err, "models: unable to delete all from djangoAdminLog slice")
	}

	return nil
}

func (o *DjangoAdminLog) ReloadGP() {
	if err := o.ReloadG(); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) ReloadP(exec boil.Executor) {
	if err := o.Reload(exec); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLog) ReloadG() error {
	if o == nil {
		return errors.New("models: no DjangoAdminLog provided for reload")
	}

	return o.Reload(boil.GetDB())
}

func (o *DjangoAdminLog) Reload(exec boil.Executor) error {
	ret, err := FindDjangoAdminLog(exec, o.ID)
	if err != nil {
		return err
	}

	*o = *ret
	return nil
}

func (o *DjangoAdminLogSlice) ReloadAllGP() {
	if err := o.ReloadAllG(); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLogSlice) ReloadAllP(exec boil.Executor) {
	if err := o.ReloadAll(exec); err != nil {
		panic(boil.WrapErr(err))
	}
}

func (o *DjangoAdminLogSlice) ReloadAllG() error {
	if o == nil {
		return errors.New("models: empty DjangoAdminLogSlice provided for reload all")
	}

	return o.ReloadAll(boil.GetDB())
}

func (o *DjangoAdminLogSlice) ReloadAll(exec boil.Executor) error {
	if o == nil || len(*o) == 0 {
		return nil
	}

	djangoAdminLogs := DjangoAdminLogSlice{}
	var args []interface{}
	for _, obj := range *o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), djangoAdminLogPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := fmt.Sprintf(
		"SELECT `django_admin_log`.* FROM `django_admin_log` WHERE (%s) IN (%s)",
		strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, djangoAdminLogPrimaryKeyColumns), ","),
		strmangle.Placeholders(dialect.IndexPlaceholders, len(*o)*len(djangoAdminLogPrimaryKeyColumns), 1, len(djangoAdminLogPrimaryKeyColumns)),
	)

	q := queries.Raw(exec, sql, args...)

	err := q.Bind(&djangoAdminLogs)
	if err != nil {
		return errors.Wrap(err, "models: unable to reload all in DjangoAdminLogSlice")
	}

	*o = djangoAdminLogs

	return nil
}

func DjangoAdminLogExists(exec boil.Executor, id int) (bool, error) {
	var exists bool

	sql := "select exists(select 1 from `django_admin_log` where `id`=? limit 1)"

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, sql)
		fmt.Fprintln(boil.DebugWriter, id)
	}

	row := exec.QueryRow(sql, id)

	err := row.Scan(&exists)
	if err != nil {
		return false, errors.Wrap(err, "models: unable to check if django_admin_log exists")
	}

	return exists, nil
}

func DjangoAdminLogExistsG(id int) (bool, error) {
	return DjangoAdminLogExists(boil.GetDB(), id)
}

func DjangoAdminLogExistsGP(id int) bool {
	e, err := DjangoAdminLogExists(boil.GetDB(), id)
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return e
}

func DjangoAdminLogExistsP(exec boil.Executor, id int) bool {
	e, err := DjangoAdminLogExists(exec, id)
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return e
}
// This file is generated by SQLBoiler (https://github.com/vattle/sqlboiler)
// and is meant to be re-generated in place and/or deleted at any time.
// DO NOT EDIT

package models

import (
	"bytes"
	"database/sql"
	"fmt"
	"reflect"
	"strings"
	"sync"
	"time"

	"github.com/pkg/errors"
	"github.com/vattle/sqlboiler/boil"
	"github.com/vattle/sqlboiler/queries"
	"github.com/vattle/sqlboiler/queries/qm"
	"github.com/vattle/sqlboiler/strmangle"
	"gopkg.in/nullbio/null.v6"
)

// DjangoAdminLog is an object representing the database table.
type DjangoAdminLog struct {
	ID            int         `boil:"id" json:"id" toml:"id" yaml:"id"`
	ActionTime    time.Time   `boil:"action_time" json:"action_time" toml:"action_time" yaml:"action_time"`
	UserID        int         `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"`
	ContentTypeID null.Int    `boil:"content_type_id" json:"content_type_id,omitempty" toml:"content_type_id" yaml:"content_type_id,omitempty"`
	ObjectID      null.String `boil:"object_id" json:"object_id,omitempty" toml:"object_id" yaml:"object_id,omitempty"`
	ObjectRepr    string      `boil:"object_repr" json:"object_repr" toml:"object_repr" yaml:"object_repr"`
	ActionFlag    int16       `boil:"action_flag" json:"action_flag" toml:"action_flag" yaml:"action_flag"`
	ChangeMessage string      `boil:"change_message" json:"change_message" toml:"change_message" yaml:"change_message"`

	R *djangoAdminLogR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L djangoAdminLogL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

// djangoAdminLogR is where relationships are stored.
type djangoAdminLogR struct {
	ContentType *DjangoContentType
	User        *AuthUser
}

// djangoAdminLogL is where Load methods for each relationship are stored.
type djangoAdminLogL struct{}

var (
	djangoAdminLogColumns               = []string{"id", "action_time", "user_id", "content_type_id", "object_id", "object_repr", "action_flag", "change_message"}
	djangoAdminLogColumnsWithoutDefault = []string{"action_time", "user_id", "content_type_id", "object_id", "object_repr", "action_flag", "change_message"}
	djangoAdminLogColumnsWithDefault    = []string{"id"}
	djangoAdminLogPrimaryKeyColumns     = []string{"id"}
)

type (
	// DjangoAdminLogSlice is an alias for a slice of pointers to DjangoAdminLog.
	// This should generally be used opposed to []DjangoAdminLog.
	DjangoAdminLogSlice []*DjangoAdminLog

	djangoAdminLogQuery struct {
		*queries.Query
	}
)

// Cache for insert, update and upsert
var (
	djangoAdminLogType                 = reflect.TypeOf(&DjangoAdminLog{})
	djangoAdminLogMapping              = queries.MakeStructMapping(djangoAdminLogType)
	djangoAdminLogPrimaryKeyMapping, _ = queries.BindMapping(djangoAdminLogType, djangoAdminLogMapping, djangoAdminLogPrimaryKeyColumns)
	djangoAdminLogInsertCacheMut       sync.RWMutex
	djangoAdminLogInsertCache          = make(map[string]insertCache)
	djangoAdminLogUpdateCacheMut       sync.RWMutex
	djangoAdminLogUpdateCache          = make(map[string]updateCache)
	djangoAdminLogUpsertCacheMut       sync.RWMutex
	djangoAdminLogUpsertCache          = make(map[string]insertCache)
)

var (
	// Force time package dependency for automated UpdatedAt/CreatedAt.
	_ = time.Second
	// Force bytes in case of primary key column that uses []byte (for relationship compares)
	_ = bytes.MinRead
)

// OneP returns a single djangoAdminLog record from the query, and panics on error.
func (q djangoAdminLogQuery) OneP() *DjangoAdminLog {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return o
}

// One returns a single djangoAdminLog record from the query.
func (q djangoAdminLogQuery) One() (*DjangoAdminLog, error) {
	o := &DjangoAdminLog{}

	queries.SetLimit(q.Query, 1)

	err := q.Bind(o)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "models: failed to execute a one query for django_admin_log")
	}

	return o, nil
}

// AllP returns all DjangoAdminLog records from the query, and panics on error.
func (q djangoAdminLogQuery) AllP() DjangoAdminLogSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return o
}

// All returns all DjangoAdminLog records from the query.
func (q djangoAdminLogQuery) All() (DjangoAdminLogSlice, error) {
	var o DjangoAdminLogSlice

	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "models: failed to assign all query results to DjangoAdminLog slice")
	}

	return o, nil
}

// CountP returns the count of all DjangoAdminLog records in the query, and panics on error.
func (q djangoAdminLogQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return c
}

// Count returns the count of all DjangoAdminLog records in the query.
func (q djangoAdminLogQuery) Count() (int64, error) {
	var count int64

	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)

	err := q.Query.QueryRow().Scan(&count)
	if err != nil {
		return 0, errors.Wrap(err, "models: failed to count django_admin_log rows")
	}

	return count, nil
}

// Exists checks if the row exists in the table, and panics on error.
func (q djangoAdminLogQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return e
}

// Exists checks if the row exists in the table.
func (q djangoAdminLogQuery) Exists() (bool, error) {
	var count int64

	queries.SetCount(q.Query)
	queries.SetLimit(q.Query, 1)

	err := q.Query.QueryRow().Scan(&count)
	if err != nil {
		return false, errors.Wrap(err, "models: failed to check if django_admin_log exists")
	}

	return count > 0, nil
}

// ContentTypeG pointed to by the foreign key.
func (o *DjangoAdminLog) ContentTypeG(mods ...qm.QueryMod) djangoContentTypeQuery {
	return o.ContentType(boil.GetDB(), mods...)
}

// ContentType pointed to by the foreign key.
func (o *DjangoAdminLog) ContentType(exec boil.Executor, mods ...qm.QueryMod) djangoContentTypeQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.ContentTypeID),
	}

	queryMods = append(queryMods, mods...)

	query := DjangoContentTypes(exec, queryMods...)
	queries.SetFrom(query.Query, "`django_content_type`")

	return query
}

// UserG pointed to by the foreign key.
func (o *DjangoAdminLog) UserG(mods ...qm.QueryMod) authUserQuery {
	return o.User(boil.GetDB(), mods...)
}

// User pointed to by the foreign key.
func (o *DjangoAdminLog) User(exec boil.Executor, mods ...qm.QueryMod) authUserQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.UserID),
	}

	queryMods = append(queryMods, mods...)

	query := AuthUsers(exec, queryMods...)
	queries.SetFrom(query.Query, "`auth_user`")

	return query
}

// LoadContentType allows an eager lookup of values, cached into the
// loaded structs of the objects.
func (djangoAdminLogL) LoadContentType(e boil.Executor, singular bool, maybeDjangoAdminLog interface{}) error {
	var slice []*DjangoAdminLog
	var object *DjangoAdminLog

	count := 1
	if singular {
		object = maybeDjangoAdminLog.(*DjangoAdminLog)
	} else {
		slice = *maybeDjangoAdminLog.(*DjangoAdminLogSlice)
		count = len(slice)
	}

	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &djangoAdminLogR{}
		}
		args[0] = object.ContentTypeID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &djangoAdminLogR{}
			}
			args[i] = obj.ContentTypeID
		}
	}

	query := fmt.Sprintf(
		"select * from `django_content_type` where `id` in (%s)",
		strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
	)

	if boil.DebugMode {
		fmt.Fprintf(boil.DebugWriter, "%s\n%v\n", query, args)
	}

	results, err := e.Query(query, args...)
	if err != nil {
		return errors.Wrap(err, "failed to eager load DjangoContentType")
	}
	defer results.Close()

	var resultSlice []*DjangoContentType
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice DjangoContentType")
	}

	if len(resultSlice) == 0 {
		return nil
	}

	if singular {
		object.R.ContentType = resultSlice[0]
		return nil
	}

	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.ContentTypeID.Int == foreign.ID {
				local.R.ContentType = foreign
				break
			}
		}
	}

	return nil
}

// LoadUser allows an eager lookup of values, cached into the
// loaded structs of the objects.
func (djangoAdminLogL) LoadUser(e boil.Executor, singular bool, maybeDjangoAdminLog interface{}) error {
	var slice []*DjangoAdminLog
	var object *DjangoAdminLog

	count := 1
	if singular {
		object = maybeDjangoAdminLog.(*DjangoAdminLog)
	} else {
		slice = *maybeDjangoAdminLog.(*DjangoAdminLogSlice)
		count = len(slice)
	}

	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &djangoAdminLogR{}
		}
		args[0] = object.UserID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &djangoAdminLogR{}
			}
			args[i] = obj.UserID
		}
	}

	query := fmt.Sprintf(
		"select * from `auth_user` where `id` in (%s)",
		strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
	)

	if boil.DebugMode {
		fmt.Fprintf(boil.DebugWriter, "%s\n%v\n", query, args)
	}

	results, err := e.Query(query, args...)
	if err != nil {
		return errors.Wrap(err, "failed to eager load AuthUser")
	}
	defer results.Close()

	var resultSlice []*AuthUser
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice AuthUser")
	}

	if len(resultSlice) == 0 {
		return nil
	}

	if singular {
		object.R.User = resultSlice[0]
		return nil
	}

	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.UserID == foreign.ID {
				local.R.User = foreign
				break
			}
		}
	}

	return nil
}

// SetContentTypeG of the django_admin_log to the related item.
// Sets o.R.ContentType to related.
// Adds o to related.R.ContentTypeDjangoAdminLogs.
// Uses the global database handle.
func (o *DjangoAdminLog) SetContentTypeG(insert bool, related *DjangoContentType) error {
	return o.SetContentType(boil.GetDB(), insert, related)
}

// SetContentTypeP of the django_admin_log to the related item.
// Sets o.R.ContentType to related.
// Adds o to related.R.ContentTypeDjangoAdminLogs.
// Panics on error.
func (o *DjangoAdminLog) SetContentTypeP(exec boil.Executor, insert bool, related *DjangoContentType) {
	if err := o.SetContentType(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}

// SetContentTypeGP of the django_admin_log to the related item.
// Sets o.R.ContentType to related.
// Adds o to related.R.ContentTypeDjangoAdminLogs.
// Uses the global database handle and panics on error.
func (o *DjangoAdminLog) SetContentTypeGP(insert bool, related *DjangoContentType) {
	if err := o.SetContentType(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}

// SetContentType of the django_admin_log to the related item.
// Sets o.R.ContentType to related.
// Adds o to related.R.ContentTypeDjangoAdminLogs.
func (o *DjangoAdminLog) SetContentType(exec boil.Executor, insert bool, related *DjangoContentType) error {
	var err error
	if insert {
		if err = related.Insert(exec); err != nil {
			return errors.Wrap(err, "failed to insert into foreign table")
		}
	}

	updateQuery := fmt.Sprintf(
		"UPDATE `django_admin_log` SET %s WHERE %s",
		strmangle.SetParamNames("`", "`", 0, []string{"content_type_id"}),
		strmangle.WhereClause("`", "`", 0, djangoAdminLogPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.ID}

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, updateQuery)
		fmt.Fprintln(boil.DebugWriter, values)
	}

	if _, err = exec.Exec(updateQuery, values...); err != nil {
		return errors.Wrap(err, "failed to update local table")
	}

	o.ContentTypeID.Int = related.ID
	o.ContentTypeID.Valid = true

	if o.R == nil {
		o.R = &djangoAdminLogR{
			ContentType: related,
		}
	} else {
		o.R.ContentType = related
	}

	if related.R == nil {
		related.R = &djangoContentTypeR{
			ContentTypeDjangoAdminLogs: DjangoAdminLogSlice{o},
		}
	} else {
		related.R.ContentTypeDjangoAdminLogs = append(related.R.ContentTypeDjangoAdminLogs, o)
	}

	return nil
}

// RemoveContentTypeG relationship.
// Sets o.R.ContentType to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Uses the global database handle.
func (o *DjangoAdminLog) RemoveContentTypeG(related *DjangoContentType) error {
	return o.RemoveContentType(boil.GetDB(), related)
}

// RemoveContentTypeP relationship.
// Sets o.R.ContentType to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Panics on error.
func (o *DjangoAdminLog) RemoveContentTypeP(exec boil.Executor, related *DjangoContentType) {
	if err := o.RemoveContentType(exec, related); err != nil {
		panic(boil.WrapErr(err))
	}
}

// RemoveContentTypeGP relationship.
// Sets o.R.ContentType to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Uses the global database handle and panics on error.
func (o *DjangoAdminLog) RemoveContentTypeGP(related *DjangoContentType) {
	if err := o.RemoveContentType(boil.GetDB(), related); err != nil {
		panic(boil.WrapErr(err))
	}
}

// RemoveContentType relationship.
// Sets o.R.ContentType to nil.
// Removes o from all passed in related items' relationships struct (Optional).
func (o *DjangoAdminLog) RemoveContentType(exec boil.Executor, related *DjangoContentType) error {
	var err error

	o.ContentTypeID.Valid = false
	if err = o.Update(exec, "content_type_id"); err != nil {
		o.ContentTypeID.Valid = true
		return errors.Wrap(err, "failed to update local table")
	}

	o.R.ContentType = nil
	if related == nil || related.R == nil {
		return nil
	}

	for i, ri := range related.R.ContentTypeDjangoAdminLogs {
		if o.ContentTypeID.Int != ri.ContentTypeID.Int {
			continue
		}

		ln := len(related.R.ContentTypeDjangoAdminLogs)
		if ln > 1 && i < ln-1 {
			related.R.ContentTypeDjangoAdminLogs[i] = related.R.ContentTypeDjangoAdminLogs[ln-1]
		}
		related.R.ContentTypeDjangoAdminLogs = related.R.ContentTypeDjangoAdminLogs[:ln-1]
		break
	}
	return nil
}

// SetUserG of the django_admin_log to the related item.
// Sets o.R.User to related.
// Adds o to related.R.UserDjangoAdminLogs.
// Uses the global database handle.
func (o *DjangoAdminLog) SetUserG(insert bool, related *AuthUser) error {
	return o.SetUser(boil.GetDB(), insert, related)
}

// SetUserP of the django_admin_log to the related item.
// Sets o.R.User to related.
// Adds o to related.R.UserDjangoAdminLogs.
// Panics on error.
func (o *DjangoAdminLog) SetUserP(exec boil.Executor, insert bool, related *AuthUser) {
	if err := o.SetUser(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}

// SetUserGP of the django_admin_log to the related item.
// Sets o.R.User to related.
// Adds o to related.R.UserDjangoAdminLogs.
// Uses the global database handle and panics on error.
func (o *DjangoAdminLog) SetUserGP(insert bool, related *AuthUser) {
	if err := o.SetUser(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}

// SetUser of the django_admin_log to the related item.
// Sets o.R.User to related.
// Adds o to related.R.UserDjangoAdminLogs.
func (o *DjangoAdminLog) SetUser(exec boil.Executor, insert bool, related *AuthUser) error {
	var err error
	if insert {
		if err = related.Insert(exec); err != nil {
			return errors.Wrap(err, "failed to insert into foreign table")
		}
	}

	updateQuery := fmt.Sprintf(
		"UPDATE `django_admin_log` SET %s WHERE %s",
		strmangle.SetParamNames("`", "`", 0, []string{"user_id"}),
		strmangle.WhereClause("`", "`", 0, djangoAdminLogPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.ID}

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, updateQuery)
		fmt.Fprintln(boil.DebugWriter, values)
	}

	if _, err = exec.Exec(updateQuery, values...); err != nil {
		return errors.Wrap(err, "failed to update local table")
	}

	o.UserID = related.ID

	if o.R == nil {
		o.R = &djangoAdminLogR{
			User: related,
		}
	} else {
		o.R.User = related
	}

	if related.R == nil {
		related.R = &authUserR{
			UserDjangoAdminLogs: DjangoAdminLogSlice{o},
		}
	} else {
		related.R.UserDjangoAdminLogs = append(related.R.UserDjangoAdminLogs, o)
	}

	return nil
}

// DjangoAdminLogsG retrieves all records.
func DjangoAdminLogsG(mods ...qm.QueryMod) djangoAdminLogQuery {
	return DjangoAdminLogs(boil.GetDB(), mods...)
}

// DjangoAdminLogs retrieves all the records using an executor.
func DjangoAdminLogs(exec boil.Executor, mods ...qm.QueryMod) djangoAdminLogQuery {
	mods = append(mods, qm.From("`django_admin_log`"))
	return djangoAdminLogQuery{NewQuery(exec, mods...)}
}

// FindDjangoAdminLogG retrieves a single record by ID.
func FindDjangoAdminLogG(id int, selectCols ...string) (*DjangoAdminLog, error) {
	return FindDjangoAdminLog(boil.GetDB(), id, selectCols...)
}

// FindDjangoAdminLogGP retrieves a single record by ID, and panics on error.
func FindDjangoAdminLogGP(id int, selectCols ...string) *DjangoAdminLog {
	retobj, err := FindDjangoAdminLog(boil.GetDB(), id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return retobj
}

// FindDjangoAdminLog retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindDjangoAdminLog(exec boil.Executor, id int, selectCols ...string) (*DjangoAdminLog, error) {
	djangoAdminLogObj := &DjangoAdminLog{}

	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from `django_admin_log` where `id`=?", sel,
	)

	q := queries.Raw(exec, query, id)

	err := q.Bind(djangoAdminLogObj)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "models: unable to select from django_admin_log")
	}

	return djangoAdminLogObj, nil
}

// FindDjangoAdminLogP retrieves a single record by ID with an executor, and panics on error.
func FindDjangoAdminLogP(exec boil.Executor, id int, selectCols ...string) *DjangoAdminLog {
	retobj, err := FindDjangoAdminLog(exec, id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return retobj
}

// InsertG a single record. See Insert for whitelist behavior description.
func (o *DjangoAdminLog) InsertG(whitelist ...string) error {
	return o.Insert(boil.GetDB(), whitelist...)
}

// InsertGP a single record, and panics on error. See Insert for whitelist
// behavior description.
func (o *DjangoAdminLog) InsertGP(whitelist ...string) {
	if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}

// InsertP a single record using an executor, and panics on error. See Insert
// for whitelist behavior description.
func (o *DjangoAdminLog) InsertP(exec boil.Executor, whitelist ...string) {
	if err := o.Insert(exec, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}

// Insert a single record using an executor.
// Whitelist behavior: If a whitelist is provided, only those columns supplied are inserted
// No whitelist behavior: Without a whitelist, columns are inferred by the following rules:
// - All columns without a default value are included (i.e. name, age)
// - All columns with a default, but non-zero are included (i.e. health = 75)
func (o *DjangoAdminLog) Insert(exec boil.Executor, whitelist ...string) error {
	if o == nil {
		return errors.New("models: no django_admin_log provided for insertion")
	}

	var err error

	nzDefaults := queries.NonZeroDefaultSet(djangoAdminLogColumnsWithDefault, o)

	key := makeCacheKey(whitelist, nzDefaults)
	djangoAdminLogInsertCacheMut.RLock()
	cache, cached := djangoAdminLogInsertCache[key]
	djangoAdminLogInsertCacheMut.RUnlock()

	if !cached {
		wl, returnColumns := strmangle.InsertColumnSet(
			djangoAdminLogColumns,
			djangoAdminLogColumnsWithDefault,
			djangoAdminLogColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)

		cache.valueMapping, err = queries.BindMapping(djangoAdminLogType, djangoAdminLogMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(djangoAdminLogType, djangoAdminLogMapping, returnColumns)
		if err != nil {
			return err
		}
		cache.query = fmt.Sprintf("INSERT INTO `django_admin_log` (`%s`) VALUES (%s)", strings.Join(wl, "`,`"), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))

		if len(cache.retMapping) != 0 {
			cache.retQuery = fmt.Sprintf("SELECT `%s` FROM `django_admin_log` WHERE %s", strings.Join(returnColumns, "`,`"), strmangle.WhereClause("`", "`", 0, djangoAdminLogPrimaryKeyColumns))
		}
	}

	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, vals)
	}

	result, err := exec.Exec(cache.query, vals...)

	if err != nil {
		return errors.Wrap(err, "models: unable to insert into django_admin_log")
	}

	var lastID int64
	var identifierCols []interface{}

	if len(cache.retMapping) == 0 {
		goto CacheNoHooks
	}

	lastID, err = result.LastInsertId()
	if err != nil {
		return ErrSyncFail
	}

	o.ID = int(lastID)
	if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == djangoAdminLogMapping["ID"] {
		goto CacheNoHooks
	}

	identifierCols = []interface{}{
		o.ID,
	}

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.retQuery)
		fmt.Fprintln(boil.DebugWriter, identifierCols...)
	}

	err = exec.QueryRow(cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
	if err != nil {
		return errors.Wrap(err, "models: unable to populate default values for django_admin_log")
	}

CacheNoHooks:
	if !cached {
		djangoAdminLogInsertCacheMut.Lock()
		djangoAdminLogInsertCache[key] = cache
		djangoAdminLogInsertCacheMut.Unlock()
	}

	return nil
}

// UpdateG a single DjangoAdminLog record. See Update for
// whitelist behavior description.
func (o *DjangoAdminLog) UpdateG(whitelist ...string) error {
	return o.Update(boil.GetDB(), whitelist...)
}

// UpdateGP a single DjangoAdminLog record.
// UpdateGP takes a whitelist of column names that should be updated.
// Panics on error. See Update for whitelist behavior description.
func (o *DjangoAdminLog) UpdateGP(whitelist ...string) {
	if err := o.Update(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}

// UpdateP uses an executor to update the DjangoAdminLog, and panics on error.
// See Update for whitelist behavior description.
func (o *DjangoAdminLog) UpdateP(exec boil.Executor, whitelist ...string) {
	err := o.Update(exec, whitelist...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
}

// Update uses an executor to update the DjangoAdminLog.
// Whitelist behavior: If a whitelist is provided, only the columns given are updated.
// No whitelist behavior: Without a whitelist, columns are inferred by the following rules:
// - All columns are inferred to start with
// - All primary keys are subtracted from this set
// Update does not automatically update the record in case of default values. Use .Reload()
// to refresh the records.
func (o *DjangoAdminLog) Update(exec boil.Executor, whitelist ...string) error {
	var err error
	key := makeCacheKey(whitelist, nil)
	djangoAdminLogUpdateCacheMut.RLock()
	cache, cached := djangoAdminLogUpdateCache[key]
	djangoAdminLogUpdateCacheMut.RUnlock()

	if !cached {
		wl := strmangle.UpdateColumnSet(djangoAdminLogColumns, djangoAdminLogPrimaryKeyColumns, whitelist)
		if len(wl) == 0 {
			return errors.New("models: unable to update django_admin_log, could not build whitelist")
		}

		cache.query = fmt.Sprintf("UPDATE `django_admin_log` SET %s WHERE %s",
			strmangle.SetParamNames("`", "`", 0, wl),
			strmangle.WhereClause("`", "`", 0, djangoAdminLogPrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(djangoAdminLogType, djangoAdminLogMapping, append(wl, djangoAdminLogPrimaryKeyColumns...))
		if err != nil {
			return err
		}
	}

	values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, values)
	}

	_, err = exec.Exec(cache.query, values...)
	if err != nil {
		return errors.Wrap(err, "models: unable to update django_admin_log row")
	}

	if !cached {
		djangoAdminLogUpdateCacheMut.Lock()
		djangoAdminLogUpdateCache[key] = cache
		djangoAdminLogUpdateCacheMut.Unlock()
	}

	return nil
}

// UpdateAllP updates all rows with matching column names, and panics on error.
func (q djangoAdminLogQuery) UpdateAllP(cols M) {
	if err := q.UpdateAll(cols); err != nil {
		panic(boil.WrapErr(err))
	}
}

// UpdateAll updates all rows with the specified column values.
func (q djangoAdminLogQuery) UpdateAll(cols M) error {
	queries.SetUpdate(q.Query, cols)

	_, err := q.Query.Exec()
	if err != nil {
		return errors.Wrap(err, "models: unable to update all for django_admin_log")
	}

	return nil
}

// UpdateAllG updates all rows with the specified column values.
func (o DjangoAdminLogSlice) UpdateAllG(cols M) error {
	return o.UpdateAll(boil.GetDB(), cols)
}

// UpdateAllGP updates all rows with the specified column values, and panics on error.
func (o DjangoAdminLogSlice) UpdateAllGP(cols M) {
	if err := o.UpdateAll(boil.GetDB(), cols); err != nil {
		panic(boil.WrapErr(err))
	}
}

// UpdateAllP updates all rows with the specified column values, and panics on error.
func (o DjangoAdminLogSlice) UpdateAllP(exec boil.Executor, cols M) {
	if err := o.UpdateAll(exec, cols); err != nil {
		panic(boil.WrapErr(err))
	}
}

// UpdateAll updates all rows with the specified column values, using an executor.
func (o DjangoAdminLogSlice) UpdateAll(exec boil.Executor, cols M) error {
	ln := int64(len(o))
	if ln == 0 {
		return nil
	}

	if len(cols) == 0 {
		return errors.New("models: update all requires at least one column argument")
	}

	colNames := make([]string, len(cols))
	args := make([]interface{}, len(cols))

	i := 0
	for name, value := range cols {
		colNames[i] = name
		args[i] = value
		i++
	}

	// Append all of the primary key values for each column
	for _, obj := range o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), djangoAdminLogPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := fmt.Sprintf(
		"UPDATE `django_admin_log` SET %s WHERE (`id`) IN (%s)",
		strmangle.SetParamNames("`", "`", 0, colNames),
		strmangle.Placeholders(dialect.IndexPlaceholders, len(o)*len(djangoAdminLogPrimaryKeyColumns), len(colNames)+1, len(djangoAdminLogPrimaryKeyColumns)),
	)

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, sql)
		fmt.Fprintln(boil.DebugWriter, args...)
	}

	_, err := exec.Exec(sql, args...)
	if err != nil {
		return errors.Wrap(err, "models: unable to update all in djangoAdminLog slice")
	}

	return nil
}

// UpsertG attempts an insert, and does an update or ignore on conflict.
func (o *DjangoAdminLog) UpsertG(updateColumns []string, whitelist ...string) error {
	return o.Upsert(boil.GetDB(), updateColumns, whitelist...)
}

// UpsertGP attempts an insert, and does an update or ignore on conflict. Panics on error.
func (o *DjangoAdminLog) UpsertGP(updateColumns []string, whitelist ...string) {
	if err := o.Upsert(boil.GetDB(), updateColumns, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}

// UpsertP attempts an insert using an executor, and does an update or ignore on conflict.
// UpsertP panics on error.
func (o *DjangoAdminLog) UpsertP(exec boil.Executor, updateColumns []string, whitelist ...string) {
	if err := o.Upsert(exec, updateColumns, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}

// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
func (o *DjangoAdminLog) Upsert(exec boil.Executor, updateColumns []string, whitelist ...string) error {
	if o == nil {
		return errors.New("models: no django_admin_log provided for upsert")
	}

	nzDefaults := queries.NonZeroDefaultSet(djangoAdminLogColumnsWithDefault, o)

	// Build cache key in-line uglily - mysql vs postgres problems
	buf := strmangle.GetBuffer()
	for _, c := range updateColumns {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	for _, c := range whitelist {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	for _, c := range nzDefaults {
		buf.WriteString(c)
	}
	key := buf.String()
	strmangle.PutBuffer(buf)

	djangoAdminLogUpsertCacheMut.RLock()
	cache, cached := djangoAdminLogUpsertCache[key]
	djangoAdminLogUpsertCacheMut.RUnlock()

	var err error

	if !cached {
		var ret []string
		whitelist, ret = strmangle.InsertColumnSet(
			djangoAdminLogColumns,
			djangoAdminLogColumnsWithDefault,
			djangoAdminLogColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)
		update := strmangle.UpdateColumnSet(
			djangoAdminLogColumns,
			djangoAdminLogPrimaryKeyColumns,
			updateColumns,
		)
		if len(update) == 0 {
			return errors.New("models: unable to upsert django_admin_log, could not build update column list")
		}

		cache.query = queries.BuildUpsertQueryMySQL(dialect, "django_admin_log", update, whitelist)
		cache.retQuery = fmt.Sprintf(
			"SELECT %s FROM `django_admin_log` WHERE `id`=?",
			strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, ret), ","),
		)

		cache.valueMapping, err = queries.BindMapping(djangoAdminLogType, djangoAdminLogMapping, whitelist)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(djangoAdminLogType, djangoAdminLogMapping, ret)
			if err != nil {
				return err
			}
		}
	}

	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)
	var returns []interface{}
	if len(cache.retMapping) != 0 {
		returns = queries.PtrsFromMapping(value, cache.retMapping)
	}

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, vals)
	}

	result, err := exec.Exec(cache.query, vals...)

	if err != nil {
		return errors.Wrap(err, "models: unable to upsert for django_admin_log")
	}

	var lastID int64
	var identifierCols []interface{}

	if len(cache.retMapping) == 0 {
		goto CacheNoHooks
	}

	lastID, err = result.LastInsertId()
	if err != nil {
		return ErrSyncFail
	}

	o.ID = int(lastID)
	if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == djangoAdminLogMapping["ID"] {
		goto CacheNoHooks
	}

	identifierCols = []interface{}{
		o.ID,
	}

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.retQuery)
		fmt.Fprintln(boil.DebugWriter, identifierCols...)
	}

	err = exec.QueryRow(cache.retQuery, identifierCols...).Scan(returns...)
	if err != nil {
		return errors.Wrap(err, "models: unable to populate default values for django_admin_log")
	}

CacheNoHooks:
	if !cached {
		djangoAdminLogUpsertCacheMut.Lock()
		djangoAdminLogUpsertCache[key] = cache
		djangoAdminLogUpsertCacheMut.Unlock()
	}

	return nil
}

// DeleteP deletes a single DjangoAdminLog record with an executor.
// DeleteP will match against the primary key column to find the record to delete.
// Panics on error.
func (o *DjangoAdminLog) DeleteP(exec boil.Executor) {
	if err := o.Delete(exec); err != nil {
		panic(boil.WrapErr(err))
	}
}

// DeleteG deletes a single DjangoAdminLog record.
// DeleteG will match against the primary key column to find the record to delete.
func (o *DjangoAdminLog) DeleteG() error {
	if o == nil {
		return errors.New("models: no DjangoAdminLog provided for deletion")
	}

	return o.Delete(boil.GetDB())
}

// DeleteGP deletes a single DjangoAdminLog record.
// DeleteGP will match against the primary key column to find the record to delete.
// Panics on error.
func (o *DjangoAdminLog) DeleteGP() {
	if err := o.DeleteG(); err != nil {
		panic(boil.WrapErr(err))
	}
}

// Delete deletes a single DjangoAdminLog record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *DjangoAdminLog) Delete(exec boil.Executor) error {
	if o == nil {
		return errors.New("models: no DjangoAdminLog provided for delete")
	}

	args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), djangoAdminLogPrimaryKeyMapping)
	sql := "DELETE FROM `django_admin_log` WHERE `id`=?"

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, sql)
		fmt.Fprintln(boil.DebugWriter, args...)
	}

	_, err := exec.Exec(sql, args...)
	if err != nil {
		return errors.Wrap(err, "models: unable to delete from django_admin_log")
	}

	return nil
}

// DeleteAllP deletes all rows, and panics on error.
func (q djangoAdminLogQuery) DeleteAllP() {
	if err := q.DeleteAll(); err != nil {
		panic(boil.WrapErr(err))
	}
}

// DeleteAll deletes all matching rows.
func (q djangoAdminLogQuery) DeleteAll() error {
	if q.Query == nil {
		return errors.New("models: no djangoAdminLogQuery provided for delete all")
	}

	queries.SetDelete(q.Query)

	_, err := q.Query.Exec()
	if err != nil {
		return errors.Wrap(err, "models: unable to delete all from django_admin_log")
	}

	return nil
}

// DeleteAllGP deletes all rows in the slice, and panics on error.
func (o DjangoAdminLogSlice) DeleteAllGP() {
	if err := o.DeleteAllG(); err != nil {
		panic(boil.WrapErr(err))
	}
}

// DeleteAllG deletes all rows in the slice.
func (o DjangoAdminLogSlice) DeleteAllG() error {
	if o == nil {
		return errors.New("models: no DjangoAdminLog slice provided for delete all")
	}
	return o.DeleteAll(boil.GetDB())
}

// DeleteAllP deletes all rows in the slice, using an executor, and panics on error.
func (o DjangoAdminLogSlice) DeleteAllP(exec boil.Executor) {
	if err := o.DeleteAll(exec); err != nil {
		panic(boil.WrapErr(err))
	}
}

// DeleteAll deletes all rows in the slice, using an executor.
func (o DjangoAdminLogSlice) DeleteAll(exec boil.Executor) error {
	if o == nil {
		return errors.New("models: no DjangoAdminLog slice provided for delete all")
	}

	if len(o) == 0 {
		return nil
	}

	var args []interface{}
	for _, obj := range o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), djangoAdminLogPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := fmt.Sprintf(
		"DELETE FROM `django_admin_log` WHERE (%s) IN (%s)",
		strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, djangoAdminLogPrimaryKeyColumns), ","),
		strmangle.Placeholders(dialect.IndexPlaceholders, len(o)*len(djangoAdminLogPrimaryKeyColumns), 1, len(djangoAdminLogPrimaryKeyColumns)),
	)

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, sql)
		fmt.Fprintln(boil.DebugWriter, args)
	}

	_, err := exec.Exec(sql, args...)
	if err != nil {
		return errors.Wrap(err, "models: unable to delete all from djangoAdminLog slice")
	}

	return nil
}

// ReloadGP refetches the object from the database and panics on error.
func (o *DjangoAdminLog) ReloadGP() {
	if err := o.ReloadG(); err != nil {
		panic(boil.WrapErr(err))
	}
}

// ReloadP refetches the object from the database with an executor. Panics on error.
func (o *DjangoAdminLog) ReloadP(exec boil.Executor) {
	if err := o.Reload(exec); err != nil {
		panic(boil.WrapErr(err))
	}
}

// ReloadG refetches the object from the database using the primary keys.
func (o *DjangoAdminLog) ReloadG() error {
	if o == nil {
		return errors.New("models: no DjangoAdminLog provided for reload")
	}

	return o.Reload(boil.GetDB())
}

// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *DjangoAdminLog) Reload(exec boil.Executor) error {
	ret, err := FindDjangoAdminLog(exec, o.ID)
	if err != nil {
		return err
	}

	*o = *ret
	return nil
}

// ReloadAllGP refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
// Panics on error.
func (o *DjangoAdminLogSlice) ReloadAllGP() {
	if err := o.ReloadAllG(); err != nil {
		panic(boil.WrapErr(err))
	}
}

// ReloadAllP refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
// Panics on error.
func (o *DjangoAdminLogSlice) ReloadAllP(exec boil.Executor) {
	if err := o.ReloadAll(exec); err != nil {
		panic(boil.WrapErr(err))
	}
}

// ReloadAllG refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
func (o *DjangoAdminLogSlice) ReloadAllG() error {
	if o == nil {
		return errors.New("models: empty DjangoAdminLogSlice provided for reload all")
	}

	return o.ReloadAll(boil.GetDB())
}

// ReloadAll refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
func (o *DjangoAdminLogSlice) ReloadAll(exec boil.Executor) error {
	if o == nil || len(*o) == 0 {
		return nil
	}

	djangoAdminLogs := DjangoAdminLogSlice{}
	var args []interface{}
	for _, obj := range *o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), djangoAdminLogPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := fmt.Sprintf(
		"SELECT `django_admin_log`.* FROM `django_admin_log` WHERE (%s) IN (%s)",
		strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, djangoAdminLogPrimaryKeyColumns), ","),
		strmangle.Placeholders(dialect.IndexPlaceholders, len(*o)*len(djangoAdminLogPrimaryKeyColumns), 1, len(djangoAdminLogPrimaryKeyColumns)),
	)

	q := queries.Raw(exec, sql, args...)

	err := q.Bind(&djangoAdminLogs)
	if err != nil {
		return errors.Wrap(err, "models: unable to reload all in DjangoAdminLogSlice")
	}

	*o = djangoAdminLogs

	return nil
}

// DjangoAdminLogExists checks if the DjangoAdminLog row exists.
func DjangoAdminLogExists(exec boil.Executor, id int) (bool, error) {
	var exists bool

	sql := "select exists(select 1 from `django_admin_log` where `id`=? limit 1)"

	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, sql)
		fmt.Fprintln(boil.DebugWriter, id)
	}

	row := exec.QueryRow(sql, id)

	err := row.Scan(&exists)
	if err != nil {
		return false, errors.Wrap(err, "models: unable to check if django_admin_log exists")
	}

	return exists, nil
}

// DjangoAdminLogExistsG checks if the DjangoAdminLog row exists.
func DjangoAdminLogExistsG(id int) (bool, error) {
	return DjangoAdminLogExists(boil.GetDB(), id)
}

// DjangoAdminLogExistsGP checks if the DjangoAdminLog row exists. Panics on error.
func DjangoAdminLogExistsGP(id int) bool {
	e, err := DjangoAdminLogExists(boil.GetDB(), id)
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return e
}

// DjangoAdminLogExistsP checks if the DjangoAdminLog row exists. Panics on error.
func DjangoAdminLogExistsP(exec boil.Executor, id int) bool {
	e, err := DjangoAdminLogExists(exec, id)
	if err != nil {
		panic(boil.WrapErr(err))
	}

	return e
}
