📅  最后修改于: 2023-12-03 15:21:20.767000             🧑  作者: Mango
YesNo Django is a Python package that provides an easy way to add yes/no fields to your Django models.
pip install yesno-django
YesNoField
from yesno_django.models
.YesNoField
to your model.from yesno_django.models import YesNoField
from django.db import models
class MyModel(models.Model):
my_field = YesNoField()
YesNoField
value using True
or False
.verbose_true
and verbose_false
arguments.from yesno_django.models import YesNoField
from django.db import models
class MyModel(models.Model):
my_field = YesNoField(verbose_true='Enabled', verbose_false='Disabled')
from yesno_django.models import YesNoField
from django.db import models
class Blog(models.Model):
title = models.CharField(max_length=255)
public = YesNoField()
def __str__(self):
return self.title
In this example, the Blog
model has a public
field of type YesNoField
. This field can be either True
or False
. When creating a new Blog
object, you can set the public
field using either True
or False
. You can also customize the yes/no labels by passing the verbose_true
and verbose_false
arguments to the YesNoField
constructor.