开发者

Can I change the default value of editable from True to False in Django models

I know I can explicity set the field option editable False on a value. For example

name = models.CharField(editable=False)

But is it possible to change the default value of a field option. So for, example editable would be False by default an开发者_JAVA技巧d I would have to explicitly set it True to make the field editable?


Create a new Field class called DefaultNotEditableCharField which inherits everything from CharField but overrides editable=False.

Personally, I'd say suck it up and type 'editable=False' everywhere you want editable to be False, since that's the documented way to do it and it'll be what people expect.


One approach would be to make the field editable by default and exclude the field from the form class you'll be using to edit the model, or make the field read-only at the form level.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜