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?

Advertisements

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

name item type items active
item1 15.0 True
item2 15.0 False

change values row active use jquery or django file view.py:

name item type items active
item1 15.0 displayed
item2 15.0 stope

help please

>Solution :

The most elegant way is likely to specify choices for the BooleanField, so:

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.

Leave a ReplyCancel reply