Checklist
Steps to reproduce
run shell command
django-admin startproject forboolean
cd forboolean
django-admin startapp boolean
boolean/models.py
from django.db import models
from rest_framework import serializers
from rest_framework import viewsets
from rest_framework import permissions
''' not good example but make it small '''
class TestBoolean(models.Model):
acknowledged = models.BooleanField(null=True, blank=True)
autoRenewing = models.NullBooleanField()
class TestBooleanSerializer(serializers.ModelSerializer):
class Meta:
model = TestBoolean
fields = '__all__'
class TestBooleanViewSet(viewsets.ModelViewSet):
queryset = TestBoolean.objects.all()
serializer_class = TestBooleanSerializer
permission_classes = [permissions.AllowAny]
add app in forboolean/settings.py
'rest_framework',
'boolean',
modify forboolean/urls.py
from django.urls import path, include
from boolean.models import TestBooleanViewSet
from rest_framework import routers
router = routers.DefaultRouter()
router.register(r'boolean', TestBooleanViewSet)
urlpatterns = [
path('', include(router.urls)),
]
run shell command
./manage.py makemigrations boolean
./manage migrate
./manage runserver
stdout
......
WARNINGS:
boolean.TestBoolean.autoRenewing: (fields.W903) NullBooleanField is deprecated. Support for it (except in historical migrations) will be removed in Django 4.0.
HINT: Use BooleanField(null=True) instead.
......
Expected behavior
django doc https://docs.djangoproject.com/en/3.1/ref/models/fields/#booleanfield
class BooleanField(**options)¶
A true/false field.
The default form widget for this field is CheckboxInput, or NullBooleanSelect if null=True.
The default value of BooleanField is None when Field.default isn’t defined.

Actual behavior
django rest framework doc
When using HTML encoded form input be aware that omitting a value will always be treated as setting a field to False, even if it has a default=True option specified. This is because HTML checkbox inputs represent the unchecked state by omitting the value, so REST framework treats omission as if it is an empty checkbox input.
Note that Django 2.1 removed the blank kwarg from models.BooleanField. Prior to Django 2.1 models.BooleanField fields were always blank=True. Thus since Django 2.1 default serializers.BooleanField instances will be generated without the required kwarg (i.e. equivalent to required=True) whereas with previous versions of Django, default BooleanField instances will be generated with a required=False option. If you want to control this behaviour manually, explicitly declare the BooleanField on the serializer class, or use the extra_kwargs option to set the required flag.


Checklist
masterbranch of Django REST framework.Steps to reproduce
run shell command
boolean/models.py
add app in forboolean/settings.py
modify forboolean/urls.py
run shell command
stdout
Expected behavior
django doc https://docs.djangoproject.com/en/3.1/ref/models/fields/#booleanfield
class BooleanField(**options)¶
A true/false field.
The default form widget for this field is CheckboxInput, or NullBooleanSelect if null=True.
The default value of BooleanField is None when Field.default isn’t defined.
Actual behavior
django rest framework doc
When using HTML encoded form input be aware that omitting a value will always be treated as setting a field to False, even if it has a default=True option specified. This is because HTML checkbox inputs represent the unchecked state by omitting the value, so REST framework treats omission as if it is an empty checkbox input.
Note that Django 2.1 removed the blank kwarg from models.BooleanField. Prior to Django 2.1 models.BooleanField fields were always blank=True. Thus since Django 2.1 default serializers.BooleanField instances will be generated without the required kwarg (i.e. equivalent to required=True) whereas with previous versions of Django, default BooleanField instances will be generated with a required=False option. If you want to control this behaviour manually, explicitly declare the BooleanField on the serializer class, or use the extra_kwargs option to set the required flag.