orm insert skip auto_now_add when user custom a value

This commit is contained in:
slene 2014-02-20 13:45:31 +08:00 committed by asta.xie
parent 5be22a99a8
commit 430a0a971f
1 changed files with 5 additions and 0 deletions

View File

@ -144,6 +144,11 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
switch fi.fieldType {
case TypeDateField, TypeDateTimeField:
if fi.auto_now || fi.auto_now_add && insert {
if insert {
if t, ok := value.(time.Time); ok && !t.IsZero() {
break
}
}
tnow := time.Now()
d.ins.TimeToDB(&tnow, tz)
value = tnow