Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would i create an active/inactive booleanfield in my django model?

I am new to django and python. I am creating a job board application and would like to have an option for users to check whether their post is active or inactive. I will be using the BooleanField, but my question is how to I have it read Active or Inactive rather than True or False

like image 752
pizzarob Avatar asked Feb 16 '23 00:02

pizzarob


1 Answers

In model you can write

from django.utils.translation import ugettext_lazy as _
class MyModel(models.Model):
    INACTIVE = 0
    ACTIVE = 1
    STATUS = (
        (INACTIVE, _('Inactive')),
        (ACTIVE, _('Active')),
    )

    active  = models.IntegerField(default=0, choices=STATUS)

And instead of IntegerField you can use BooleanField. Then INACTIVE/ACTIVE is True/False

like image 126
Tarer Avatar answered Apr 07 '23 15:04

Tarer