Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading