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