📜  yesno django - Python (1)

📅  最后修改于: 2023-12-03 15:21:20.767000             🧑  作者: Mango

YesNo Django - Python

YesNo Django is a Python package that provides an easy way to add yes/no fields to your Django models.

Features
  • Simple and easy to use.
  • Supports all major databases.
  • Customizable yes/no labels.
Installation
pip install yesno-django
Usage
  1. Import the YesNoField from yesno_django.models.
  2. Add the YesNoField to your model.
from yesno_django.models import YesNoField
from django.db import models

class MyModel(models.Model):
    my_field = YesNoField()
  1. Access the YesNoField value using True or False.
  2. Customize the yes/no labels using the 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')
Example
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.