django model DateTime友好设置

    create_time = models.DateTimeField(auto_now_add=True, editable=False)
    update_time = models.DateTimeField(auto_now=True, editable=False, db_index=True)

数据的创建时间设置为auto_now_add,在创建数据的时候自动添加当前时间,editable=False禁止编辑

数据的修改时间设置为auto_now,在修改数据的时候自动修改为当前时间

注意本地时间格式,如果需要修改为中国时间,则需修改settings.py文件

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = False

猜你喜欢

转载自blog.csdn.net/qq_41572228/article/details/85644598
今日推荐