auto_now和modelform

model中设置了auto_now=True或auto_now_add=True会使该自动将字段的editable属性置为Fasle

文档(delvelopment版本)

As currently implemented, setting auto_now or auto_now_add to True will cause the field to have editable=False and blank=True set.

字段editable设置为false后将不会被modelform展现出来,也不会被验证是否合法

文档(delvelopment版本)

editable¶

Field.editable¶
If False, the field will not be displayed in the admin or any other ModelForm. They are also skipped during model validation. Default is True.

源码

        if not getattr(f, 'editable', False):
            if (fields is not None and f.name in fields and
                    (exclude is None or f.name not in exclude)):
                raise FieldError(
                    "'%s' cannot be specified for %s model form as it is a non-editable field" % (
                        f.name, model.__name__)
                )
            continue
     ....

如果editable是false,会直接continue(不考虑里面的if的话),不会将该字段加入field_list数组中

转载于:https://www.cnblogs.com/songbird/p/8268240.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值