4

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

4

2 回答 2

6

在模型中你可以写

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)

您可以使用 BooleanField 代替 IntegerField。那么 INACTIVE/ACTIVE 是 True/False

于 2013-10-12T20:39:19.427 回答
2

您可以使用label

is_active = forms.BooleanField(label='Active?')
于 2013-10-12T20:34:54.297 回答