开发者

How to work on this particular situation in django admin?

开发者 https://www.devze.com 2023-01-28 16:56 出处:网络
class Foo(models.Model): bar_protected = models.BooleanField(default=False) bar = models.CharField(max_length=50
class Foo(models.Model):
    bar_protected = models.BooleanField(default=False)
    bar = models.CharField(max_length=50

Here I am customizing django admin. Now I have two fiel开发者_StackOverflow中文版d in the model. By Default I want that 'bar' remains disabled. (Not Hide). And bar_protected unchecked. When some one checked bar_protected , bar enabled.

    Django have disabled facilities But when I do, It hides the bar Field. 

Thanks in advance.


You should either use editable = False in the model for that field or put it in readonly_fields while registering the model in the admin.py file. This should work.

0

精彩评论

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

关注公众号