[英]How do I change the value of true or false to a text value type it I am checking the row in the entire table Note the table is of type datatables?
use django How do I change the value of true or false to a text value type it I am checking the row in the entire table使用 django 如何将 true 或 false 的值更改为文本值类型我正在检查整个表中的行
name item![]() |
type items![]() |
active![]() |
---|---|---|
item1![]() |
15.0 ![]() |
True![]() |
item2![]() |
15.0 ![]() |
False![]() |
change values row active use jquery or django file view.py:更改值行活动使用 jquery 或 django 文件 view.py:
name item![]() |
type items![]() |
active![]() |
---|---|---|
item1![]() |
15.0 ![]() |
displayed![]() |
item2![]() |
15.0 ![]() |
stope![]() |
help please请帮忙
The most elegant way is likely to specify choices for the BooleanField
, so:最优雅的方法可能是为
BooleanField
指定选择,因此:
from django.db import models
ACTIVE_CHOICES = [
(False, 'stope')
, (True, 'displayed')
]
class MyModel(models.Model):
# …
active = models.BooleanField(choices=ACTIVE_CHOICES)
Then you can render the corresponding label in a template with:然后你可以在模板中渲染相应的标签:
{{ mymodelobject.get_active_display }}
It will also use these choices by default in a ModelForm
, ModelAdmin
, and serializers.默认情况下,它还将在
ModelForm
、 ModelAdmin
和序列化程序中使用这些选项。
Without code, it is difficult to give a precise answer.没有代码,很难给出准确的答案。
but the easiest way to set value based on a boolean in javascript is to use a ternary operator.但是在javascript中基于布尔值设置值的最简单方法是使用三元运算符。
If true, active will be set to "displayed", if false, active will be set to "stope"如果为 true,active 将设置为“displayed”,如果为 false,active 将设置为“stope”
active = boolean_value ?活动 = 布尔值? "displayed" : "stope"
“显示”:“采场”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.